how can convert vector to array

how can convert vector to array ; Ex:
a = [ 1 2 3 ];
i like to convert it to :
d = [ 1 0 0;
0 2 0;
0 0 3;
1 2 0;
1 0 3;
0 2 3;
1 2 3 ];
thanks

3 comentarios

Walter Roberson
Walter Roberson el 23 de Ag. de 2015
How important is that order? Some of the other orders of the same kind of setup are much easier.
In a duplicate question, the poster asked
Ex:
w = [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ]
I like to convert it to
g= [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
0 0 3 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 ;
......until......... ;
0 0 3 4 5 6 7 8 9 10 11 12 13 14 15;
0 2 3 4 5 6 7 8 9 10 11 12 13 14 15;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
that mean I have , rows=2^(2n-1) I got answer from _ the cyclist_ http://www.mathworks.com/matlabcentral/answers/235359-how-can-convert-vector-to- array . it was good answer, but it was active until 5 elements [ 1 2 3 4 5 ]. thank you - the cyclist _

Iniciar sesión para comentar.

Respuestas (1)

the cyclist
the cyclist el 23 de Ag. de 2015
If the exact ordering is not important, then you could do
P = perms([1 2 3 0 0])
Q = unique(sort(P(:,1:3),2),'rows')

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 23 de Ag. de 2015

Comentada:

el 23 de Ag. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by