I am unable to display my output for my graph.

1 view (last 30 days)
Why is the following not displaying my output? Please help.
t = [0:0.01:20];
Vo = 90;
angle = [10 25 45 65 85];
g = 9.81;
yo = 0; mm = 0;
for theta = angle
Xposition = Vo*cosd(theta)*t;
Yposition = ( -(1/2)*g*(t.^2) ) + Vo*sind(theta)*t + yo;
plot(t,Yposition,'DisplayName',int2str(theta));
if max(Yposition(Yposition>=1)) > mm
mm = max(Yposition);
endif
hold on;
endfor
axis([0 inf 0 mm+20])
xlabel('Time(s)');
ylabel('Projectile Height(m)')
legend hold off;

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 24 Sep 2021
Edited: Sulaymon Eshkabilov on 24 Sep 2021
Here is a corrected code:
t = 0:0.01:20;
Vo = 90;
angle = [10 25 45 65 85];
g = 9.81; yo = 0; mm = 0;
for theta = angle
Xposition = Vo*cosd(theta)*t;
Yposition = ( -(1/2)*g*(t.^2) ) + Vo*sind(theta)*t + yo;
plot(t,Yposition,'DisplayName',int2str(theta));
if max(Yposition(Yposition>=1)) > mm
mm = max(Yposition);
end
axis([0 inf 0 mm+20])
xlabel('Time(s)');
ylabel('Projectile Height(m)')
hold on
end
legend
hold off

More Answers (1)

Walter Roberson
Walter Roberson on 24 Sep 2021
Because MATLAB does not have endfor or endif commands.
t = [0:0.01:20];
Vo = 90;
angle = [10 25 45 65 85];
g = 9.81;
yo = 0;
mm = 0;
for theta = angle
Xposition = Vo*cosd(theta)*t;
Yposition = ( -(1/2)*g*(t.^2) ) + Vo*sind(theta)*t + yo;
plot(t,Yposition,'DisplayName',int2str(theta));
if max(Yposition(Yposition>=1)) > mm
mm = max(Yposition);
end
hold on;
end
axis([0 inf 0 mm+20])
xlabel('Time(s)');
ylabel('Projectile Height(m)')
legend
hold off;

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!