# My plot is not showing a line?

조회 수: 7(최근 30일)
Andrei Sacal 2021년 11월 22일
댓글: the cyclist 2021년 11월 22일
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표시숨기기 이전 댓글 수: 1
Andrei Sacal 2021년 11월 22일
sorry, change "Time" to t

댓글을 달려면 로그인하십시오.

### 답변(1개)

the cyclist 2021년 11월 22일
편집: the cyclist 2021년 11월 22일
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표시숨기기 이전 댓글 수: 1
the cyclist 2021년 11월 22일
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]) 댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!