我的代碼創建了三條數據點的「線」,但不會將這些點連接成線!我看過教程,嘗試了諸如plot(Time,CurrentSpeed1,' - ')和添加標記之類的東西,但無論如何,它總是有三個不相連的點的顏色系列。這是我得到的:爲什麼Matlab中的2D數據點不能成爲線?
Time = 0;
while (Acceleration1 > 0.012 || Acceleration2 > 0.012 || Acceleration3 > 0.012)
Drag = (1/2) * AirDensity * (CurrentSpeed1^2) * DragCoefficient * Area;
Force = EnginePower/CurrentSpeed1;
Acceleration1 = (Force-Drag)/EmptyWeight;
CurrentSpeed1 = CurrentSpeed1 + Acceleration1;
Drag = (1/2) * AirDensity * (CurrentSpeed2^2) * DragCoefficient * Area;
Force = EnginePower/CurrentSpeed2;
Acceleration2 = (Force-Drag)/HalfWeight;
CurrentSpeed2 = CurrentSpeed2 + Acceleration2;
Drag = (1/2) * AirDensity * (CurrentSpeed3^2) * DragCoefficient * Area;
Force = EnginePower/CurrentSpeed3;
Acceleration3 = (Force-Drag)/FullWeight;
CurrentSpeed3 = CurrentSpeed3 + Acceleration3;
plot(Time, CurrentSpeed1, Time, CurrentSpeed2, Time, CurrentSpeed3);
Time = Time + 1;
hold on
end
xlabel('Time (Seconds)');
ylabel('Speed (m/s)');
hold off
爲什麼哦爲什麼?歡呼:)
So..hang on ...什麼是OldTime?陣列在哪裏? – Magicaxis 2013-04-30 16:58:24
爲了通過一條直線連接兩個點,您需要爲plot命令提供矢量形式的兩個點的x和y值(即:plot([xpt1 xpt2],[ypt1 ypt2]);')。我正在做的'OldTime','OldSpeed1'等正在存儲您的點的以前的xy值,以便我可以將舊座標和新座標都傳遞給繪圖命令。這將連接你的兩個點 – anonymous 2013-04-30 17:01:19
存儲每個值的數組像@shoelzer說是另一種方式來做同樣的事情;而不是在循環內逐步繪製它,然後繪製整個事件 – anonymous 2013-04-30 17:06:27