how do I add error bars to points on a scatter line using their means
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ibrahim Steel
il 15 Ott 2016
Commentato: Star Strider
il 15 Ott 2016
I am new to using MATLAB, and i need to plot experimental data, but cant manage to plot error bars. say I have the data set, x = 1, y = 1,2,3 - x = 2, y = 4, 5, 6, etc. i want to plot a graph of x against the mean of y at that point, (so in the first case, x = 1, ybar = 2, etc), but i need to add standard error bars that are calculated using the variation in y for each given point of x. is there any way of doing this?
Thanks
0 Commenti
Risposta accettata
Star Strider
il 15 Ott 2016
The errorbar function may do what you want:
x = 1:3; % Independent Variable
y = [1 2 3 % Dependent Variable Matrix
4 5 6
7 8 9];
y_mean = mean(y,2); % Mean
y_se = sqrt(var(y,[],2)/size(y,2)); % Standard Error Of The Mean (Data At Each ‘x’ Are Rows)
figure(1)
errorbar(x, y_mean, y_se)
grid
axis([0 4 ylim])
Note — In the mean, var, and size function calls, the ‘2’ refers to calculating or referencing along the rows (so calculating it for each row) of the ‘y’ matrix.
If you wanted to calculate down the columns instead, you would either use ‘1’ or use nothing at all, since calculating down the columns is the way MATLAB does its calculations (by default).
2 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Bar Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!