convert matrix in single column
1.801 views (last 30 days)
Show older comments
Hi, I have to convert a matrix in one column vector composed of all the columns of the original matrix. How can I do this? Thanks
5 Comments
Image Analyst
on 9 Apr 2020
You said "I have to convert a matrix in one column vector composed of all the columns of the original matrix." I thought you meant you had a column vector and had to convert it to a matrix having the same number of columns as the original matrix from where the column vector came. In other words, I thought you meant "I have to convert a matrix of one column vector INTO ONE composed of all the columns of the original matrix."
Seeing the answer you accepted, it appears that you actually meant "I have to convert a matrix INTO a one column vector that is composed of all the columns of the original matrix." Leaving out seemingly minor words completely changes the interpretation of the question, as does their placement in the sentence.
Accepted Answer
More Answers (5)
Image Analyst
on 18 Apr 2012
If your column vector was "composed of all the columns of the original matrix", then use the reshape() command to turn it from a column vector back into the original 2D matrix.
matrix2D = reshape(columnVector, [rows columns]);
(The converse, how to get the column vector in the first place (what you may have done to get your vector) is accomplished like this columnVector = fullMatrix(:).)
7 Comments
Kyril Kaufmann
on 26 Apr 2020
For a more algorithmic solution:
% From matrix to vector
N = 10;
mat1 = rand(N);
vec1 = zeros(N*N,1);
for i=1:N
for j=1:N
vec1((i-1)*N + j) = mat1(i,j);
end
end
% From vector to matrix
N = 10;
vec2 = rand(N*N,1);
mat2 = zeros(N);
for i=1:N
for j=1:N
mat2(i,j) = vec2((i-1)*N + j);
end
end
0 Comments
AMIR KHFAGI
on 23 Mar 2020
Hi, I have to convert one column vector to a matrix in matlab. How can I do this?
abbas karimi
on 25 Feb 2022
A= 7 4 8 6, 9 3 0 2 , 1 5 6 3
B= 8 7 4 0 , 9 6 2 5 , 1 4 7 2
C= 1 9 0 2, 7 4 6 5 , 3 8 7 1
D= 7 6 3 , 9 5 1 , 0 2 4 , 7 6 1
E= 0 5 2 , 9 8 1 , 6 4 3 , 0 7 5 ,
F= 9 2 1, 0 4 3, 7 6 5, 4 1 8
- AB + (DE)T
- (E+F)T – (D + F)T
- Bt - (A + C)’
- DT * Et
1 Comment
Image Analyst
on 26 Feb 2022
I think you posted this in the wrong place. Your "Answer" doesn't seem to answer the original question at all. It's not even MATLAB code.
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!