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].

29 visualizzazioni (ultimi 30 giorni)
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 Commenti
Jan
Jan il 18 Ott 2015
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 il 19 Ott 2015
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.

Accedi per commentare.

Risposta accettata

SOUMEN ATTA
SOUMEN ATTA il 19 Ott 2015
Modificato: Walter Roberson il 19 Ott 2015
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

Più risposte (0)

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by