在组中排序元素 - MATLAB

Agr*_*ror 1 arrays sorting matlab matrix-indexing

我有一个数组A xy值.. e,g.

A = 
    5  1
    7  2
    3  1
    5  3
    4  4
    7  3
    2  5
    9  5
    7  6
Run Code Online (Sandbox Code Playgroud)

我需要一次取三个值,然后根据x值按升序对它们进行排序(前3个x y值接下来3个x y值,依此类推.)

我想按此顺序 -

3  1
5  1
7  2
4  4
5  3
7  3
2  5
7  6
9  5
Run Code Online (Sandbox Code Playgroud)

有人可以建议我使用MATLAB代码来获得所需的结果吗?

谢谢

Div*_*kar 5

看看这是否适合你 -

N = 3; %// group-size
[~,ind] = sort(reshape(A(:,1),N,[])) %// get sorted indices for the x values as 
                                     %// groups of N elements
Aout = A(bsxfun(@plus,ind,[0:(size(A,1)/N)-1]*N),:) %// get sorted indices for all
%// x values as a whole and use them to index into rows of A to get the desired output
Run Code Online (Sandbox Code Playgroud)

当然,它假设行数可以被整除N.