Plotting error bars?

4 visualizzazioni (ultimi 30 giorni)
George Smith
George Smith il 9 Apr 2018
Commentato: the cyclist il 3 Mar 2022
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')

Risposte (1)

the cyclist
the cyclist il 9 Apr 2018
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 Commenti
Tre Davidson
Tre Davidson il 3 Mar 2022
no it does not
the cyclist
the cyclist il 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.

Accedi per commentare.

Categorie

Scopri di più su Line 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!

Translated by