Convert matrix in single column/row vector
Mostrar comentarios más antiguos
Hi, I have to convert a matrix in one column/row vector composed of all the rows of the original matrix. How can I do this? Thanks. For example, to convert [1 2; 3 4] in to [1 2 3 4].
Respuesta aceptada
Más respuestas (4)
M Shujah Islam Sameem
el 5 de En. de 2019
18 votos
%%%% Converting Matix to vector
A = [1 2 3; 4 5 6; 7 8 9] % Example matrix
reshape(A,[],1) % convert matrix to column vector
reshape(A,1,[]) % convert matrix to row vector
2 comentarios
Samaa Yasser
el 7 de Abr. de 2021
@M Shujah Islam Sameem excuse me ,, i want to convert image matrix size 256x256 to row vector with length same size can you please help me ?
Rik
el 7 de Abr. de 2021
'the same size', do you mean a vector length 256 or 65536? In the latter case, read the answer.
Muhammad Usman
el 23 de Dic. de 2019
9 votos
A = [1 2; 3 4];
B = A(:) % convert the matrix into a column vector
C = A(:)' % convert the matrix into a row matrix
2 comentarios
Paolo Mulazzani
el 8 de Mzo. de 2020
not work: instead of 1 2 3 4 the result is 1 3 2 4
Muhammad Usman
el 9 de Mzo. de 2020
A=[1 2; 3 4];
A=A';
A(:)
Fariha Tabassum
el 6 de Abr. de 2020
8 votos
A = [1 2; 3 4];
B = A';
C = reshape(B,1,[])
ans of C will be [1 2 3 4]
2 comentarios
Yezi Kadhim
el 9 de Mayo de 2021
Exactly what I wanted!.
A million Thanks!
rishav baishya
el 26 de En. de 2022
thanks a lot
Çağatay Murat Yılmaz
el 4 de Oct. de 2020
1 voto
You can convert the following matrix to a vector using the following code.
input matrix:
0 1 0 2 3
4 5 6 7 8
9 10 11 12 13
output vector:
0 1 0 2 3 4 5 6 7 8 9 10 11 12 13
code:
vector=[];
for i=1:size(matrix,1)
vector=[vector matrix(i,:)];
end
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!