Given a=[1 2 3 4 5], generate m=[2 1 3 4 5; 2 3 1 4 5; 2 3 4 1 5; 2 3 4 5 1; 1 3 2 4 5; 1 3 4 2 5; 1 3 4 5 2; 1 2 4 3 5; 1 2 4 5 3; 1 2 3 5 4].

조회 수: 28 (최근 30일)
Given a=[1 2 3 4 5], generate
m=[2 1 3 4 5;
2 3 1 4 5;
2 3 4 1 5;
2 3 4 5 1;
1 3 2 4 5;
1 3 4 2 5;
1 3 4 5 2;
1 2 4 3 5;
1 2 4 5 3;
1 2 3 5 4].
What will be the Matlab code to generate 'm' from 'a'?
  댓글 수: 2
Jan
Jan 2015년 10월 18일
Please explain the relation between the input and the output. Why are these 10 permutations chosen, and not the other ones?
SOUMEN ATTA
SOUMEN ATTA 2015년 10월 19일
There is a relation between i/p and o/p. Observe the first 4 rows of 'm'. In these 4 rows only the first element of 'a', i.e., '1' is shifted to its right one place at a time. Then observe the 5th to 7th row of 'm' where the second element of 'a', i.e., '2' is shifted to its right one place at a time and so on up to the second last element.

댓글을 달려면 로그인하십시오.

채택된 답변

SOUMEN ATTA
SOUMEN ATTA 2015년 10월 19일
편집: Walter Roberson 2015년 10월 19일
Please find the answer of the question asked by me.
Given a=[1 2 3 4 5], generate m=[2 1 3 4 5; 2 3 1 4 5; 2 3 4 1 5; 2 3 4 5 1; 1 3 2 4 5; 1 3 4 2 5; 1 3 4 5 2; 1 2 4 3 5; 1 2 4 5 3; 1 2 3 5 4].
m=[];
k=1;
for i=1:n-1
aa=a;
aa(i)=[];
for j=i+1:n
mm=[];
mm=[aa(1:j-1),a(i),aa(j:n-1)];
m(k,:)=mm;
k=k+1;
end
end

추가 답변 (0개)

카테고리

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