how to get permutation of each rows of matrix

3 次查看(过去 30 天)
hi
I want to get a matrix which consists all permutation of each rows of previous matrix... For example,
A =
1 2 2
2 2 3
result =
1 2 2
2 1 2
2 2 1
2 2 3
2 3 2
3 2 2

采纳的回答

Andrei Bobrov
Andrei Bobrov 2013-5-21
out = [];
for j1 = 1:size(A,1)
out = [out;unique(perms(A(j1,:)),'rows')];
end

更多回答(1 个)

Thomas
Thomas 2013-5-21
a=[ 1 2 2
2 2 3];
for ii=1:size(a,1)
q(ii,:,:)=unique(perms(a(ii,:)),'rows');
end
out = reshape(q,[],size(a,2),1)
  1 个评论
frwmetric
frwmetric 2013-5-21
If I have an row like [a,a,a] your answer gives an error. Why? And do you have any idea how can I fix it?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by