Error using plot Vectors must be the same length.

5 ビュー (過去 30 日間)
Emma Windsor
Emma Windsor 2019 年 8 月 15 日
回答済み: Sourav Bairagya 2019 年 8 月 19 日
Hi I am pretty new to Matlab and I am trying to plot Acceleration and driving style against time however the time vector is not the same size. I'm not sure how I fix this.
figure(3);
plot(t_sec,Acceleration,'r');
hold on
plot(t_sec,ds_mapping,'c');
Acceleration 1x620
ds_mapping 1x620
t_sec 621x1
Please could you advise?
Thanks.
  3 件のコメント
Guillaume
Guillaume 2019 年 8 月 15 日
編集済み: Guillaume 2019 年 8 月 15 日
Well, you need to find out why the two are not the same length when they should be. It's not something we can answer, and what you should do will depend entirely on what that answer is.
Perhaps, as infinity says, you've calculated the acceleration by taking the diff of the velocity which would explain why it has one element less (in which case maybe you should have used gradient instead of diff). That doesn't explain ds_mapping.
Or perhaps the explanation is something else entirely. Maybe you've loaded the wrong time vector.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 8 月 15 日
Please share complete code.

サインインしてコメントする。

回答 (1 件)

Sourav Bairagya
Sourav Bairagya 2019 年 8 月 19 日
In your code, “Acceleration” and “ds_mapping”are row vectors whether “t_sec” is a column vector.
Hence, you should first convert “t_sec” into a row vector like “Acceleration”and “ds_mapping”.
Now, as your Y-axis data i.e. “Acceleration” and “ds_mapping” have 620 elements only, hence you should consider only the first 620 elements of your X-axis data i.e. “t_sec”.
A demo code is attached here to illustrate the whole plotting procedure mentioned above:
Acceleration=rand(1,620); % A Demo Acceleration row vector
ds_mapping=rand(1,620); % A Demo ds_mapping row vector
t_sec=rand(621,1); % A Demo t_sec column vector
t_sec=t_sec'; % converting t_sec into a row_vector
plot(t_sec(1:end-1),Acceleration); % Considering only 620 elements of t_sec and plotting
hold on;
plot(t_sec(1:end-1), ds_mapping);
hold off;

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by