1

xと値を持つ配列 A がありyます。

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

一度に 3 つの値を取得し、値に従って昇順に並べ替える必要があり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 に答える