# My plot is not showing a line?

2 views (last 30 days)
Andrei Sacal on 22 Nov 2021
Answered: VBBV on 23 Nov 2021
can you please take a look at the following code and let me know why my plot isn't showing a line?
my plot is coming out blank, Im trying to get a graph that looks like this
%constants
d1 = 28;
d2 = d1;
m = 2;
F = 10;
Vmax = 3;
nVmax = -3;
%acceleration
a=F/m;
%Time
t=d1/Vmax;
%speed
S=d1/Time;
% Graph to show velocity of cart at 10 intervals
T=0:t/10:t;
%velocity
v=a*T;
x=T;
na = a - a*2; %deceleration
t1 = Vmax/a;
t2 = nVmax/na;
s1 = (1/2)*(((Vmax)*(Vmax))/a);
s2 = (Vmax)*(t2)+((1/2)*(na)*((t2)*(t2)));
tm = t - (t1+t2);
St1 = t1 + (1/2)*(tm);
St2 = t2 + (1/2)*(tm);
plot(t1,s1);
hold on
plot(tm, Vmax);
hold on
plot(t2, s2);
hold on
plot(S,t2);
##### 2 CommentsShowHide 1 older comment
Andrei Sacal on 22 Nov 2021
sorry, change "Time" to t

the cyclist on 22 Nov 2021
Edited: the cyclist on 22 Nov 2021
Here is a modified version of your code, where I changed Time to t (in the assignment of S), and I plotted your data as large individual points:
%constants
d1 = 28;
d2 = d1;
m = 2;
F = 10;
Vmax = 3;
nVmax = -3;
%acceleration
a=F/m;
%Time
t=d1/Vmax;
%speed
S=d1/t;
% Graph to show velocity of cart at 10 intervals
T=0:t/10:t;
%velocity
v=a*T;
x=T;
na = a - a*2; %deceleration
t1 = Vmax/a;
t2 = nVmax/na;
s1 = (1/2)*(((Vmax)*(Vmax))/a);
s2 = (Vmax)*(t2)+((1/2)*(na)*((t2)*(t2)));
tm = t - (t1+t2);
St1 = t1 + (1/2)*(tm);
St2 = t2 + (1/2)*(tm);
figure
hold on
h(1) = plot(t1,s1,'.');
h(2) = plot(tm, Vmax,'.');
h(3) = plot(t2, s2,'.');
h(4) = plot(S,t2,'.');
set(h,'MarkerSize',32)
You can see that each plot was only a single point. So, when you try to plot a line "between the points", nothing shows up because there are no lines to draw.
##### 2 CommentsShowHide 1 older comment
the cyclist on 22 Nov 2021
Your plotting, when we substitute in the value of s1p, is
plot(0, [0.6 3])
is has syntax, but doesn't really make sense. You need to pair and equal number of x and y points. Like this:
plot([0 0], [0.6 3])

VBBV on 23 Nov 2021
%constants
d1 = 28;
d2 = d1;
m = 2;
F = 10;
Vmax = 3;
nVmax = -3;
%acceleration
a=F/m;
%Time
t=d1/Vmax;
%speed
S=d1/t;
% Graph to show velocity of cart at 10 intervals
T=0:t/10:t;
%velocity
v=a*T;
x=T;
na = a - a*2; %deceleration
t1 = Vmax/a;
t2 = nVmax/na;
s1 = (1/2)*(((Vmax)*(Vmax))/a);
s1p = [t1, Vmax];
tm = t - (t1+t2);
s2 = (Vmax)*(t2)+((1/2)*(na)*((t2)*(t2)));
tv = t1+tm;
s2p = [tv, Vmax];
St1 = t1 + (1/2)*(tm);
St2 = t2 + (1/2)*(tm);
plot(s1p); hold on; plot(s2p)
you can try this