MATLAB plot with sorted order
matlab, plot
Solution
Call sort with a second output argument.
x = [1 20 3 7 10]
y = [2 51 1 9 18]
[xsorted, I] = sort(x)
ysorted = y(I)
Problem
I have two vectors in MATLAB, say: ``` x = [1 20 3 7 10] ``` and ``` y = [2 51 1 9 18] ``` How can I plot `y` vs K where `x` has sorted value order (1 3 7 10 20) with their respective `y` values like the following? ``` x = [1 3 7 10 20] y = [2 1 9 18 51] ```