How to plot error bars

8 Ansichten (letzte 30 Tage)
Marcel
Marcel am 26 Aug. 2011
Hello,
Having this type of data....
time1 = [0.14 0.99 1.67 2.45 3.10 3.70 4.24 5.00]
res1 = [4 6 2 9 1 0 4 7]
time2 = [0.11 0.69 1.00 1.45 1.66 2.04 2.24 2.99 3.11 3.43 4.25
4.55 5.00]
res2 = [8 1 5 3 7 1 3 10 9 5 3 2 1]
time3 = [0.09 0.33 1.13 1.44 2.10 2.70 3.24 4.00 4.80 5.00]
res3 = [0 3 4 7 2 6 3 4 9 8]
and a solution (given by Oleg Komarov) to average it....
--------------------------------------------------------
% unique time vector
untime = 0:0.5:5;
% Idx
[trash,idx1] = histc(untime,[0 time1(1:end-1) inf]);
[trash,idx2] = histc(untime,[0 time2(1:end-1) inf]);
[trash,idx3] = histc(untime,[0 time3(1:end-1) inf]);
rep = [res1(idx1); res2(idx2); res3(idx3)];
avg = mean(rep);
hold on
% Plot all the lines
stairs(untime,rep.')
% Plot the average in black
stairs([0 untime], [9 avg],'Color','k','Linew',2)
------------------------------------------------------------------
I'd like to know how to plot error bars in this case. I was trying to use function given in matlab but the vectors dimensions don't match.
Thanks for help.
  2 Kommentare
Oleg Komarov
Oleg Komarov am 26 Aug. 2011
Where do you want your error bars, on the middle of the stair or when the stair shifts, i.e. every 0:0.5:5? What kind of error you want? max and min, std error, absolute deviation?
Marcel
Marcel am 28 Aug. 2011
I'd like to have the error bars(std error) on the middle of the stair.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Oleg Komarov
Oleg Komarov am 28 Aug. 2011
Add this line at the end:
opt = {'k','Linew',2,'LineS','none'};
x = 0.25:0.5:4.75;
y = avg(1:end-1);
errorbar(x,y,std(rep(:,1:end-1)),opt{:})
EDIT with min and max
L = y - min(rep(:,1:end-1));
U = max(rep(:,1:end-1)) - y;
errorbar(x,y,L,U,opt{:})
  2 Kommentare
Marcel
Marcel am 29 Aug. 2011
Thanks very much for your help, really appreciate it.
How would that be with min and max error?
Marcel
Marcel am 30 Aug. 2011
Thank you Oleg. Great stuff.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Arturo Moncada-Torres
Arturo Moncada-Torres am 26 Aug. 2011
I would recommend you to take a look at the following FEX submissions:
  2 Kommentare
Sean de Wolski
Sean de Wolski am 26 Aug. 2011
"healthy error bars" :)
Do healthy error bars finish their vegetables? Is TMW feeding their error bars too much candy?
Arturo Moncada-Torres
Arturo Moncada-Torres am 26 Aug. 2011
LOL, good one =)

Melden Sie sich an, um zu kommentieren.


ASMS Mat Su
ASMS Mat Su am 29 Nov. 2012
I have almost similar problem... but this time the value of L and U is on different size. I want it to be L= min and U= max value instead of std error which is only one value (+ or - value).
I tried to create a bar graphs with errorbars(min and min) instead of std error.
Any one know how to solve this?
This is my code and what I tried.
mean = [1 2 3; 4 5 NaN; 7 8 9]; min = [-0.0040 -0.0281 -0.0252; -0.0154 -0.0076 -0.0282; -0.0137 -0.0297 -0.0526]; max = [0.0470 0.0166 0.0015; 0.0015 -0.0038 0.0216; -0.0000 0.0091 0.0316 ];
figure bar(mean); colormap summer grid on hold on
x = 1:3;
y = mean;
L = min;
U = max;
errorbar(x,y,L,U);

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by