error bars on plot

4 次查看(过去 30 天)
Joseph
Joseph 2015-11-2
Hello. I am having trouble adding error bars to this plot. My code is below. I need the data "cd_water, re_water..cd_glycol, re_glycol...etc.." all to show error bars from the original loglog plot of CD vs Re. please help. thank you.
Re = logspace(-2,7,1001);
term1 = (24./Re);
term2 = ((2.6*(Re./5))./(1+((Re./5).^1.52)));
term3 = ((0.411*((Re./263000).^(-7.94)))./(1+((Re./263000).^(-8))));
term4 = ((Re.^(0.8))./461000);
CD = term1 + term2 + term3 + term4;
figure(2)
loglog(Re,CD)
grid on
xlabel('Re');ylabel('C_D');
hold on
Cd_water = [0.381, .324, 0.297, 0.214, 0.321];
Re_water = [70221.78, 41366.93,166202.97, 101691.09, 34306.93];
Cd_glycol = [.602,.757,.324,.402,.975];
Re_glycol = [3672.43,1720.25,10375.76,4843.64,1230.25];
Cd_glycerin = [45.4,130,11.4,33.1];
Re_glycerin = [12.89,4.13,57.19,17.47];
plot(Re_water,Cd_water,'*',Re_glycol,Cd_glycol,'.',Re_glycerin,Cd_glycerin,'o')
legend('Expected','Water','Glycol','Glycerin')

采纳的回答

Star Strider
Star Strider 2015-11-2
I do not see that you called the errorbar function. If you did, and you did not include it in the code you posted, how did you specify or calculate the error bars, and how did you call the errorbar function with your plots? (If you want to plot more than one plot in an axes object, for example one plot with error bars and one plot without them, you have to use the hold function.)
  2 个评论
Joseph
Joseph 2015-11-2
i have not yet called the error bar function because i do not know how to use it. the loglog plot is a curve and the other data are points. im trying to get error bars from the points to the curve.
Star Strider
Star Strider 2015-11-2
If you just want lines from the curve to the plotted points, errorbar is probably not what you want. You need to program the lines specifically. Fortunately, that isn’t difficult, but does look a bit strange. I had to make some minor changes in your code (creating anonymous functions to allow calculation of the ‘Cd’ values at the specific values of ‘Re’ of your data) to plot the vertical lines.
See if this does what you want:
Re = logspace(-2,7,1001);
term1 = @(Re) (24./Re);
term2 = @(Re) ((2.6*(Re./5))./(1+((Re./5).^1.52)));
term3 = @(Re) ((0.411*((Re./263000).^(-7.94)))./(1+((Re./263000).^(-8))));
term4 = @(Re) ((Re.^(0.8))./461000);
CD = @(Re) term1(Re) + term2(Re) + term3(Re) + term4(Re);
figure(2)
loglog(Re,CD(Re))
grid on
xlabel('Re');ylabel('C_D');
hold on
Cd_water = [0.381, .324, 0.297, 0.214, 0.321];
Re_water = [70221.78, 41366.93,166202.97, 101691.09, 34306.93];
Cd_glycol = [.602,.757,.324,.402,.975];
Re_glycol = [3672.43,1720.25,10375.76,4843.64,1230.25];
Cd_glycerin = [45.4,130,11.4,33.1];
Re_glycerin = [12.89,4.13,57.19,17.47];
plot(Re_water,Cd_water,'*',Re_glycol,Cd_glycol,'.',Re_glycerin,Cd_glycerin,'o')
hold on
plot([Re_water; Re_water], [CD(Re_water); Cd_water], '-r')
plot([Re_glycol; Re_glycol], [CD(Re_glycol); Cd_glycol], '-r')
plot([Re_glycerin; Re_glycerin], [CD(Re_glycerin); Cd_glycerin], '-r')
hold off
legend('Expected','Water','Glycol','Glycerin')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Errorbars 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by