why is my plot only showing 1 diagonal line
2 ビュー (過去 30 日間)
古いコメントを表示
clear
close all
t=0;
V = 0;
dt = 0.1;
S = 3;
CD = 0.1;
T = 10000;
m = 500;
plot(t,V)
hold on
while t<=5
t(end+1)=t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
plot(t,V)
end
while t <=10
t(end+1) = t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
plot(t,V)
end
xlabel('Time (s)')
ylabel('Speed (m/s)')
title('Plot of speed against time')
0 件のコメント
回答 (2 件)
Scott MacKenzie
2022 年 3 月 10 日
編集済み: Scott MacKenzie
2022 年 3 月 10 日
First, you probably should move the plot functions outside the while loop. Build up the vectors, then plot!
But, the reason you are seeing only one line is that the two plots are plotting the same line. Below, I demonstrate this by changing the line specs (and moving the plot function outside the loop). You can see the first line plotted in red and the 2nd line plotted on top using a thick black dashed line.
t=0;
V = 0;
dt = 0.1;
S = 3;
CD = 0.1;
T = 10000;
m = 500;
plot(t,V)
hold on
while t<=5
t(end+1)=t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
end
plot(t,V, '-r')
while t <=10
t(end+1) = t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
end
plot(t,V, '--k', 'LineWidth', 5)
xlabel('Time (s)')
ylabel('Speed (m/s)')
title('Plot of speed against time')
0 件のコメント
VBBV
2022 年 3 月 10 日
clear
close all
t=0;
V = 0;
dt = 0.1;
S = 3;
CD = 0.1;
T = 10000;
m = 500;
% plot(t,V)
hold all
while t<=10
if t<=5
t(end+1)=t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
plot(t,V,'-b')
% hold on
else
t(end+1) = t(end)+dt;
F = T - CD*V(end)^21225*S/2;
V(end+1) = V(end) + dt*F/m;
plot(t,V,'-r')
% hold on
end
t = t +1;
end
xlabel('Time (s)')
ylabel('Speed (m/s)')
title('Plot of speed against time')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Scatter Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!