Mismatched plot when editing the x-axis

This is the code I ued when opening a plot in matlab command from simulink.
plot(out.x(:,1), out.x(:,2), out.x(:,1), out.x(:,3), out.x(:,1), out.x(:,4))
The x-axis runs from 0-100, which I want to change to 1960:1.49:2060
I used
timedata=1960:1.49:2060;
so that they cover the same length.
plot(timedata, out.x(:,2), timedata, out.x(:,3), timedata, out.x(:,4));
I am not sure why there is a difference between the two graph? There shouldn't be apart from the x-axis.

2 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 4 月 6 日
Can you share the variable 'out' in a .mat file?
Light_traveller
Light_traveller 2020 年 4 月 6 日
I have attached the file.

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

 採用された回答

Walter Roberson
Walter Roberson 2020 年 4 月 6 日

0 投票

out.x(:,1) is not evenly spaced. Plot it by itself and you will see. Or look at diff(out.x(:,1))

2 件のコメント

Walter Roberson
Walter Roberson 2020 年 4 月 6 日
x1 = out.x(:,1) + 1960;
plot(x1, out.x(:,2:4));
Light_traveller
Light_traveller 2020 年 4 月 6 日
Yes, that has sorted it. Thank you.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by