Plotting error bars?

조회 수: 14 (최근 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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by