Why subplot is not working?

17 views (last 30 days)
Darkhan Sheldebayev
Darkhan Sheldebayev on 4 Dec 2019
Answered: Mahesh Taparia on 9 Dec 2019
clear
clf
clc
axis equal
hold on
velocity = input('Enter your constant velocity for v: ');
while isnan(velocity) % If your input is not a number
velocity = input('Your value is not a number.Please input your velocity for v:','s'); % Enter new input for c
end
while velocity == 0
disp('Your velocity must not be zero');
velocity = input('Enter enter true value of constant velocity for v: ');
while isnan(velocity) % If your input is not a number
velocity = input('Your value is not a number.Please input your velocity for v:','s'); % Enter new input for c
end
end
Height = input('Enter your height to explorers for H: ');
while isnan(Height) % If your input is not a number
Height = input('Your value is not a number.Please input your height for H:','s'); % Enter new input for c
end
while Height == 0
disp('Your height must not be zero');
Height = input('Enter true value of height for H: ');
while isnan(Height) % If your input is not a number
Height = input('Your value is not a number.Please input your height for H:','s'); % Enter new input for c
end
end
d = input(' Write your distance from the plane to explorers for d: ');
while isnan(d)
d = input(' Write your true distance from the plane to explorers for d: ');
end
while d == 0
disp('You lost your dropping point');
d = input(' Write your true distance from the plane to explorers for d: ');
while isnan(distance)
d = input(' Write your true distance from the plane to explorers for d: ');
end
end
v = velocity;
h = Height;
g=9.81;
t = sqrt(2*h/g);
s = v*t;
d_dp = d-s;
t_dp = d_dp/v;
t_full = d/v;
while d > s
figure(1);
subplot(2,1,1);
line([0 d+500],[0 0]);
plot(d,0,'og');
for i = 0:t_dp/10:t_dp
x=(i*v);
plot(x,h,'dr');
plot(x,h,'*k');
pause(0.5);
end
subplot(2,1,2);
x0=x;
plot(x0,h,'og');
plot([x0 x0],[0 h],'--c');
for i = 0:t/10:t
x=(i*v+x0);
y=(h-g*i^2/2);
plot(x,h,'dr');
plot(x,y,'*k');
pause(0.5);
end
xlabel('Distance','Color','r');
ylabel('Height','Color','r');
end
  2 Comments
Adam Danz
Adam Danz on 4 Dec 2019
Edited: Adam Danz on 4 Dec 2019
It's not clear what you're asking or what's not working. Code is helpful but when there's a lot of code and no explanation of what's wrong, we don't know where to start. Minimize the time we need to spend helping you by clearing defining the problem.
Check out these tips on how to maximized the help you get in this forum
Stephane
Stephane on 4 Dec 2019
If you don't make use of subplot, but use 'plot' instead in different figures. Does it work?

Sign in to comment.

Answers (1)

Mahesh Taparia
Mahesh Taparia on 9 Dec 2019
Hi Darkhan,
It seems the condition (d > s’) which you put in while loop is not satisfied, so the subplot command is not executed. Select the value of ‘d’ and ‘s’ such that the condition should satisfy in order to plot your values.
For example, set v=5, H=6 and d=25, you will get your required plot.
Hope it will help.

Tags

Community Treasure Hunt

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

Start Hunting!