Can't plot a graph no matter what I do

1 回表示 (過去 30 日間)
Farouk Omer
Farouk Omer 2021 年 1 月 16 日
編集済み: Walter Roberson 2021 年 1 月 19 日
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

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 16 日
編集済み: Walter Roberson 2021 年 1 月 19 日
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 件のコメント
Farouk Omer
Farouk Omer 2021 年 1 月 16 日
Thanks a lot! I just got it to work. You're a lifesaver.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by