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

16 visualizaciones (últimos 30 días)
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 comentarios
Jan
Jan el 18 de Oct. de 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 el 19 de Oct. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

SOUMEN ATTA
SOUMEN ATTA el 19 de Oct. de 2015
Editada: Walter Roberson el 19 de Oct. de 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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by