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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by