My plot is not showing a line?
5 ビュー (過去 30 日間)
古いコメントを表示
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 ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/809719/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/809719/image.png)
%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 件のコメント
the cyclist
2021 年 11 月 22 日
Unrecognized function or variable 'Time'.
Error in answerTest (line 16)
S=d1/Time;
========================
Should Time have been 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 件のコメント
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!