MATLAB: Error bars on plot

error barsfigureplotuncertainty

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')

Best Answer

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.)