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 Center および File ExchangeLogical についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by