How do I plot an "unarranged" array1 vs array2 in MATLAB?

35 Views Asked by At

I have to plot two arrays:

array1= [ 0.6321 0.6640 0.6997 0.8574 0.8824 0.9222 0.0893 0.1310 0.1600 0.3251 0.4008 0.7528 0.7985 0.9871 0.0417 0.2209 0.2694]

array2 = [-40.8700 -46.9600 -47.3900 -19.8500 -13.4700 -5.7820 49.4100 58.6600 63.2000 45.6000 17.8800 -45.5000 -38.9800 27.2700 32.4500 63.3800 54.7800]

As you see, the first array is unarranged, so when I plot them together this mess happens:

enter image description here

Which is obvious, since plot() join the points together and they go back and forth. How I make this problem go away? I could order the arrays, but that's not what I want (I want to plot the point, (0.6321,-40.8700),(0.6640,-46.9600), etc.).

1

There are 1 best solutions below

0
On BEST ANSWER

Try

[array1_sorted, array1_order] = sort(array1);
array2_sorted = array2(array1_order, : );