带有排序顺序的MATLAB图

bij*_*uji 2 matlab plot

我在MATLAB中有两个向量,比如说:

x = [1 20 3 7 10]  
Run Code Online (Sandbox Code Playgroud)

y = [2 51 1 9 18]  
Run Code Online (Sandbox Code Playgroud)

我如何绘制yvs K在哪里x已经按照各自的y值排序值顺序(1 3 7 10 20)?

x = [1 3 7 10 20]
y = [2 1 9 18 51]
Run Code Online (Sandbox Code Playgroud)

dev*_*van 6

使用第二个输出参数调用sort.

x = [1 20 3 7 10]  
y = [2 51 1 9 18]  

[xsorted, I] = sort(x)
ysorted = y(I)
Run Code Online (Sandbox Code Playgroud)