Plotting error bars?

4 ビュー (過去 30 日間)
George Smith
George Smith 2018 年 4 月 9 日
コメント済み: the cyclist 2022 年 3 月 3 日
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')

回答 (1 件)

the cyclist
the cyclist 2018 年 4 月 9 日
The documentation for errorbar describes how to add both horizontal and vertical error bars.
(Unless you have an older version of MATLAB, which I think might not have had horizontal bars.)
  2 件のコメント
Tre Davidson
Tre Davidson 2022 年 3 月 3 日
no it does not
the cyclist
the cyclist 2022 年 3 月 3 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by