How to plot error bars
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Oleg Komarov
le 26 Août 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?
Réponse acceptée
Oleg Komarov
le 28 Août 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{:})
Plus de réponses (2)
Arturo Moncada-Torres
le 26 Août 2011
I would recommend you to take a look at the following FEX submissions:
2 commentaires
Sean de Wolski
le 26 Août 2011
"healthy error bars" :)
Do healthy error bars finish their vegetables? Is TMW feeding their error bars too much candy?
ASMS Mat Su
le 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);
0 commentaires
Voir également
Catégories
En savoir plus sur Bar Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!