How to make a column matrix from multi-dimensional matrix with several rows
Show older comments
Hello, allow me inquire something little. Suppose i have matrix A which is100 by 30 matrix. I want to make a n by 1 matrix by transposig each row from A then concatenating to form B. Example;
A=[1 2 3 4 5;60 5 7 89 9;4 5 7 8 9;6 80 32 12 11];
B=[A(1,:);A(2,:);A(3,:);A(4,:)];
Now the sample program above was simple becaue it involved only a few row which can easily be computed, supposei have larger mtrix as the one given in the question in paragraph 1, how can I go about it? Thank you sir/ma'am.
Accepted Answer
More Answers (1)
Suppose if matrix A = [1 2 3;4 5 6] , u want a matrix B to be equal to [1 4;2 5;3 6] ie transpose each row to obatain n*1 matrix and then append to B.
U can do this by making use of simple for loop , below is the implementation:
A=[1 2 3; 4 5 6];
n = size(A,1);
B=[];
for i=1:n
C = A(i,:);
B = horzcat(B,C');
end
disp(B);
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!