Plotting error bars?
4 views (last 30 days)
Show older comments
I would like to plot error bars representing the standard deviation of x values, but at the moment the error bars on my graph are only appearing in the vertical axis? Is there anyway I can change the orientation so they are in the correct axis?
Here's the script i'm working with:
x = [12.755 9.1827 6.9252 5.4083 4.3403];
y = [408 265 236 139 124];
coeffs = polyfit(x , y, 1);
yfit = polyval(coeffs, x);
res = y - yfit ;
xfit = x;
SE = std(x)/sqrt(5);
SD = std(x)
err = [SD SD SD SD SD]
grad = (yfit(1) - yfit(5)) / (x(1) - x(5));
disp(['The gradient of the trendline = ', num2str(grad)])
errorbar(x, y, err, 'blue')
hold on
plot(x ,y, 'x', xfit, yfit, 'r-+', 'LineWidth',1.1)
set (gca, 'FontName', 'Century')
grid on
grid minor
title('Plot of buckling load vs 1/Length for fixed-fixed end condition')
ylabel('Pcr / N');
xlabel('1/L^2 / m^2')
legend('Standard Deviation', 'Data Points', 'Trendline')
0 Comments
Answers (1)
the cyclist
on 9 Apr 2018
(Unless you have an older version of MATLAB, which I think might not have had horizontal bars.)
2 Comments
the cyclist
on 3 Mar 2022
This link will take you directly to the documentation example of plotting both horizontal error bars. Here is the code:
x = 1:10:100;
y = [20 30 45 40 60 65 80 75 95 90];
err = [1 3 5 3 5 3 6 4 3 3];
errorbar(x,y,err,'horizontal')
So, I'm not sure why you claim it doesn't.
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!