I am unable to display my output for my graph.

1 visualizzazione (ultimi 30 giorni)
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;

Risposta accettata

Sulaymon Eshkabilov
Sulaymon Eshkabilov il 24 Set 2021
Modificato: Sulaymon Eshkabilov il 24 Set 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

Più risposte (1)

Walter Roberson
Walter Roberson il 24 Set 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;

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by