How can I make a better plot?

1 view (last 30 days)
HelpAStudent
HelpAStudent on 2 Oct 2021
Commented: HelpAStudent on 4 Oct 2021
Hi, I have 5 sets of data and I want to write a script that reads my 5 matrices (1x21 double) and displays a single figure that plots the mean error (y) against the gain (x) in decibel. The output of my script should has:
  • The lines for each segment should be displayed using a different color. With point where is the value on the segment.
  • A legend should be included indicating wich line corresponds to wich segment
  • Each segment should has his linear fit (courve fitting) in wich I can find the ratio between the axes
I think I have to use iteraction for a solution of this kind, but I'm not sure how.
These are my 5 data:
err20 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.08935539299999,2.06473429585112,5.31643514302866,12.1807063663099,23.4911626896201,37.8143988479465,53.0667200958471];
err40 = [1,1,1,1,1,1,1.00980392156863,1.21923952036955,1.83719863383950,3.35132045800776,6.15310998083444,10.4540779879203,16.3935058175317,24.4567825083250,34.2731876493287,44.8404803207833,56.1569894419756,67.9621753642978,80.3418716316936,92.6177152673935,105.509145868874];
err60 = [1.39130582788671,2.06089077044959,3.06870791245791,4.79824204787542,7.43102274858528,11.1839078762097,15.8879812010210,21.5982089544676,28.3128632729741,36.0451923666447,44.3639384800055,53.0905553702049,62.0750621155379,70.5611743877611,79.2822679481440,87.4151859346590,95.2561517964825,102.939651014533,111.592224212783,119.481125788707,128.101212449710];
err80 = [17.4311417284922,22.2395558126501,27.9265106941469,34.2412676054684,40.8661898327012,47.9425873245325,55.0569858602196,62.0452743182326,68.6517414695066,75.0178392624680,81.3553772590478,87.8836526599804,93.1726477983694,99.2482660012320,104.954811955097,110.618897123263,116.985855082487,123.136684599450,129.996356750259,137.015229368536,144.682941495957];
err100= [50.0098577942206,55.6474590816719,61.3114187709398,66.7658549295944,72.0226315556860,76.6917932491624,81.7675527655915,86.5206979973362,90.9380438970932,95.6093452209315,99.8809271502719,104.517882995723,109.232695936831,113.888646043589,118.823549750783,124.212683308618,129.481920951591,135.262067967506,141.525996933700,147.328685524455,153.893747639987];

Accepted Answer

C B
C B on 2 Oct 2021
Edited: C B on 3 Oct 2021
@Agnese Chini Is this fulfill your requirement?
err20 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.08935539299999,2.06473429585112,5.31643514302866,12.1807063663099,23.4911626896201,37.8143988479465,53.0667200958471];
err40 = [1,1,1,1,1,1,1.00980392156863,1.21923952036955,1.83719863383950,3.35132045800776,6.15310998083444,10.4540779879203,16.3935058175317,24.4567825083250,34.2731876493287,44.8404803207833,56.1569894419756,67.9621753642978,80.3418716316936,92.6177152673935,105.509145868874];
err60 = [1.39130582788671,2.06089077044959,3.06870791245791,4.79824204787542,7.43102274858528,11.1839078762097,15.8879812010210,21.5982089544676,28.3128632729741,36.0451923666447,44.3639384800055,53.0905553702049,62.0750621155379,70.5611743877611,79.2822679481440,87.4151859346590,95.2561517964825,102.939651014533,111.592224212783,119.481125788707,128.101212449710];
err80 = [17.4311417284922,22.2395558126501,27.9265106941469,34.2412676054684,40.8661898327012,47.9425873245325,55.0569858602196,62.0452743182326,68.6517414695066,75.0178392624680,81.3553772590478,87.8836526599804,93.1726477983694,99.2482660012320,104.954811955097,110.618897123263,116.985855082487,123.136684599450,129.996356750259,137.015229368536,144.682941495957];
err100= [50.0098577942206,55.6474590816719,61.3114187709398,66.7658549295944,72.0226315556860,76.6917932491624,81.7675527655915,86.5206979973362,90.9380438970932,95.6093452209315,99.8809271502719,104.517882995723,109.232695936831,113.888646043589,118.823549750783,124.212683308618,129.481920951591,135.262067967506,141.525996933700,147.328685524455,153.893747639987];
gain =1:21;
plot(gain,err20,'redo')
hold on
plot(gain,err40,'green*')
hold on
plot(gain,err60,'blue+')
hold on
plot(gain,err80,'cyanx')
hold on
plot(gain,err100,'magentad')
legend('err20','err40','err60','err80','err100')
ylabel('Error')
xlabel('Gain')
  5 Comments
C B
C B on 4 Oct 2021
Maybe like this
p = polyfit(gain,err100,1) ;
slope5 = p(1)
HelpAStudent
HelpAStudent on 4 Oct 2021
Thank you, it works!

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!