Can't plot a graph no matter what I do

1 visualización (últimos 30 días)
Farouk Omer
Farouk Omer el 16 de En. de 2021
Editada: Walter Roberson el 19 de En. de 2021
Hello, I have a college project and it involves plotting. I can't get the plot window to even open up despite I'm sure my code my code doesn't contain any mistakes.
Heres is the code:
clear
clc
disp('Welcome to the Projectilre Motion application')
%% error checking
% this code is for projectile motion using the following equations:
% v=u + at,v^2 = u^2 + 2as, s=ut+0.5 * at^2
disp('For the following questions, press 1 for yes and 2 for no');
check1 = input (' Does your projectile departure and landing zone share a similar height?: ');
check2 = input (' are you trying to clear a wall?: ');
check3 = input (' Is there an initial velocity?: ') ;
% error checking
%% request for inputs
if check1 == 1 && check2 ==2 && check3 ==1
u = input ('Please input the initial speed in m/s: ' );
angle = input ('Please input the initial direction in degrees: ');
ux = u.*cosd(angle);
uy = u.*sind(angle);
a = - 9.81;
% v=u + at,v^2 = u^2 + 2as, s=ut+0.5 * at^2;1/2ut^2 + ut - s = 0;
t1 = (-uy + sqrt (uy.^2-4*(1/2*uy)*0))/(a);
t2 = (-uy - sqrt (uy.^2-4*(1/2*uy)*0))/(a);
elseif check1 == 1 && check2 ==2 && check3 ==1
if t2 > t1
x = (0:1:10);
time = linspace2(0,t2,100);
Sy = uy*time + 1/2 * a .* time.^2;
Sx = ux*time;
plot(Sx,Sy, 'b-')
hold on
axis equal
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de En. de 2021
Editada: Walter Roberson el 19 de En. de 2021
if check1 == 1 && check2 ==2 && check3 ==1
elseif check1 == 1 && check2 ==2 && check3 ==1
Those are the same conditions. You can only reach the elseif when the conditions are false for the if, but when they are false they cannot be true for the elseif because they are the same.
Note: reading your prompts, people are not going to know to enter 1 or 2
  1 comentario
Farouk Omer
Farouk Omer el 16 de En. de 2021
Thanks a lot! I just got it to work. You're a lifesaver.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by