同じ次元のMatlabに2つの行列X
とG
があります。MxN
です。私は、このコードは、私がM
が大きい場合、それは遅くてもよいがMatlabの行列の各行の要素の並び替え
A(:,:,1)=X;
A(:,:,2)=G;
B=zeros (size(A,1),2*N);
for i = 1:size(A,1),
B(i,:) = reshape(sortrows(squeeze(A(i,:,:)), [-2 -1]),1,2*N);
end
を望むもの行い
clear all
rng default;
M=12;
N=3;
X=randi([0 1], M,N);
G=randi([0 1], M,N);
%for i=1,...N
% List in descending order the elements of G(i,:)
% If G(i,h)=G(i,j), then order first G(i,h) if X(i,h)>X(i,j), and
% order first G(i,j) if X(i,j)>X(i,h). If G(i,h)=G(i,j) and
% X(i,j)=X(i,h), then any order is fine.
% Use the order determined for G(i,:) to order X(i,:).
% Combine the ordered X(i,:) and G(i,:) in B(i,:)
%end
以下に説明するように、両方の各行を注文したいです。たとえば、M=8000
とN=20
の場合、約0.6秒かかるため、手順を何度も繰り返す必要があります。
あなたはより効率的な提案をしていますか?
X=[0 0 0 1;
1 1 0 0];
G=[0 1 0 1;
0 0 1 0];
B=[1 0 0 0 | 1 1 0 0;
0 1 1 0 | 1 0 0 0];
あなたは、入力と出力の小さな例を投稿する場合、それはあなたが、私が追加した –
と例望むものそれを明確にするために、役立ちます – user3285148