1

我有一个数组 A 具有xy值..例如

A = 
    5  1
    7  2
    3  1
    5  3
    4  4
    7  3
    2  5
    9  5
    7  6

我需要一次取三个值并根据值按升序对它们进行排序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

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

谢谢你

4

1 回答 1

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

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

于 2014-10-21T12:43:24.243 回答