Convert matrix in single column/row vector
이전 댓글 표시
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].
채택된 답변
추가 답변 (4개)
M Shujah Islam Sameem
2019년 1월 5일
18 개 추천
%%%% 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
Samaa Yasser
2021년 4월 7일
@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
2021년 4월 7일
'the same size', do you mean a vector length 256 or 65536? In the latter case, read the answer.
Muhammad Usman
2019년 12월 23일
9 개 추천
A = [1 2; 3 4];
B = A(:) % convert the matrix into a column vector
C = A(:)' % convert the matrix into a row matrix
댓글 수: 2
Paolo Mulazzani
2020년 3월 8일
not work: instead of 1 2 3 4 the result is 1 3 2 4
Muhammad Usman
2020년 3월 9일
A=[1 2; 3 4];
A=A';
A(:)
Fariha Tabassum
2020년 4월 6일
8 개 추천
A = [1 2; 3 4];
B = A';
C = reshape(B,1,[])
ans of C will be [1 2 3 4]
댓글 수: 2
Yezi Kadhim
2021년 5월 9일
Exactly what I wanted!.
A million Thanks!
rishav baishya
2022년 1월 26일
thanks a lot
Çağatay Murat Yılmaz
2020년 10월 4일
1 개 추천
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
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!