My plot is not showing a line?

18 views (last 30 days)
Andrei Sacal
Andrei Sacal on 22 Nov 2021
Commented: the cyclist on 22 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 Comments
the cyclist
the cyclist on 22 Nov 2021
Unrecognized function or variable 'Time'.
Error in answerTest (line 16)
S=d1/Time;
========================
Should Time have been t?
Andrei Sacal
Andrei Sacal on 22 Nov 2021
sorry, change "Time" to t

Sign in to comment.

Answers (1)

the cyclist
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 Comments
Andrei Sacal
Andrei Sacal on 22 Nov 2021
can you check this one please im trying to get it to plot a line
%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(0,s1p);
the cyclist
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])

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!