Data point in plot connecting randomly to each other

The pattern of the plot is obviously going up from 0-2 then all the way down, I do not know why are the points randomly connecting to a point further away and not connecting like it used to (by ascending order).

4 件のコメント

KSSV
KSSV 2019 年 1 月 21 日
Try sorting the data.....else attach your data and show us your expectations.
Timothy Lim
Timothy Lim 2019 年 1 月 21 日
The data is basically a 30x1 double against a 30x1 double. Must I sort the data with an ascending order to use the plot function?
I have also tried scatter and then line function but it comes down to the same result.
Capture.PNG
The dotted points obviously can be connected smoothly but MATLAB is weirdly connecting the points randomly instead.
madhan ravi
madhan ravi 2019 年 1 月 21 日
show your plot call
Timothy Lim
Timothy Lim 2019 年 1 月 21 日
plot(ratio_1,f1_1) - gives me the random connecting lines. Image in my question
plot(ratio_1,f1_1,'o') - gives me the circular data point. Image in my first reply.

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

 採用された回答

Kevin Phung
Kevin Phung 2019 年 1 月 21 日

1 投票

I would sort the x values and sort the y values based on how the x values were sorted.
You can do this with
[sorted_array sorted_order] = sort(x);
y = y(sorted_order;)

3 件のコメント

Timothy Lim
Timothy Lim 2019 年 1 月 21 日
Wow that solved the problem, I'm amaze that it was so easy to sort X and make sure that Y array will follow the sorting.
I always thought that MATLAB automatically arranges the data and interpolate it accordingly. I now know that the data has to be arranged in an ascending order for the plot function to work.
Timothy Lim
Timothy Lim 2019 年 1 月 21 日
I'll accept the answer in an hour if no one is able to give a more convenient way (no need for any sorting, direct plotting based off the array relationship).
Thanks for the answer mate.
Kevin Phung
Kevin Phung 2019 年 1 月 21 日
No problemo amigo

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

その他の回答 (0 件)

カテゴリ

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by