how can i get a horzenital vector?

X = [2 1 5 1
5 4 8 1
1 4 5 7];
if i use X1 = X(:);
the output is X1=[2
5
1
1
4
4
5
8
5
1
1
7]
but i wante the out put is X1 =[2 1 5 1 5 4 8 1 1 4 5 7];
thank you very much

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 14 de Sept. de 2011
X1 = reshape(X',1,[])

2 comentarios

Andrei Bobrov
Andrei Bobrov el 14 de Sept. de 2011
My typo! Corrected...
Thanks Fangjun!
Jan
Jan el 14 de Sept. de 2011
@Fangjun: Without the transpose, you get X1 = [2,5,1,...], but Amal wants [2,1,5,...] - the data in row order.

Iniciar sesión para comentar.

Más respuestas (2)

Daniel Shub
Daniel Shub el 14 de Sept. de 2011
If there is any chance that you matrix will have complex numbers you need to be careful with the difference between ' (ctranspose) and .' (transpose). To be clear I might go with:
X1 = transpose(X(:));
I do not know if there is a performance difference between ctranspose and transpose for real matrices.

1 comentario

Sean de Wolski
Sean de Wolski el 14 de Sept. de 2011
There is not. Though there was a bug with ctranspose in the original release of R2009b.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Sept. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by