# No line while plotting using "for" command

1 view (last 30 days)
Michalis Nearchou on 1 Nov 2019
Edited: Subhadeep Koley on 4 Nov 2019
I was trying to make a plot, but there is no line after I run it. Can anyone help with that?
mu = 0.0000181206; rho = 1.225;
vc= 15; vstall=5; vmax=1;
g=9.81;span= 1;
for w=0.5:1.5:21
for c=0.16:0.33:18
L=w*g;
S = c*span;
AR=span/c;
Cl3D=(Lift)./(0.5*rho*vc.^2*S);
Cl2D=(Cl3D)./(0.95*0.9);
Clmax3D= (Lift)./(0.5*rho.*vstall.^2*S);
Clmax2D= (Clmax3D)./(0.95.*0.9);
re=(rho*c*vc)./mu;
plot(w,Clmax2D);
end
end

darova on 1 Nov 2019
Use
plot(w,Clmax2D,'.b');
You are plotting single points at a time, and without a
hold on
instruction, so each will replace the last and you will end up with just a single point.
Nevertheless, plotting like this is very inefficient. You should just store the results from your loop in arrays and then do a single plot instruction after the loop. Even using 'hold on' would not join your dots and would give you a huge number of individual graphics objects instead of just one.

Subhadeep Koley on 4 Nov 2019
Edited: Subhadeep Koley on 4 Nov 2019
Hi, using hold on you can plot all the points in the figure.
mu = 0.0000181206; rho = 1.225;
vc= 15; vstall=5; vmax=1;
g=9.81;span= 1;
Lift = ones(1,100); % I have used a random data for the variable Lift
for w=0.5:1.5:21
for c=0.16:0.33:18
L=w*g;
S = c*span;
AR=span/c;
Cl3D=(Lift)./(0.5*rho*vc.^2*S);
Cl2D=(Cl3D)./(0.95*0.9);
Clmax3D= (Lift)./(0.5*rho.*vstall.^2*S);
Clmax2D= (Clmax3D)./(0.95.*0.9);
re=(rho*c*vc)./mu;
plot(w,Clmax2D,'*b');
hold all;
end
end
hold off;

Stephen Cobeldick on 4 Nov 2019
Note that this is quite inefficient.
Much more efficient would be to plot matrices/arrays.
Subhadeep Koley on 4 Nov 2019
Stephen Cobeldick Yes I agree. This is very inefficient.