How to construct a 3x9 matrix E from a 3x3x3 matrix D, where D(x,y,:) is the column of E?
4 views (last 30 days)
Show older comments
A = [1 2 3; 4 5 6; 7 8 9];
B = [11 22 33; 44 55 66; 77 88 99];
C = [111 222 333; 444 555 666; 777 888 999];
D = cat(3,A,B,C);
How to construct a 3x9 matrix E, where E(:,1) = D(1,1,:), E(:,2)=D(1,2,:), E(:,3)=D(1,3,:), ..., E(:,9)=D(3,3,:)?
What if D is a 3 x m x n matrix? How to construct a 2D (3x mn) matrix E from D, where D(x,y,:) becomes the column of E? Thank you.
0 Comments
Answers (1)
Image Analyst
on 8 Oct 2021
A = [1 2 3; 4 5 6; 7 8 9];
B = [11 22 33; 44 55 66; 77 88 99];
C = [111 222 333; 444 555 666; 777 888 999];
D = cat(3,A,B,C)
E = [reshape(D(:, :, 1), [], 1), reshape(D(:, :, 2), [], 1), reshape(D(:, :, 3), [], 1)]
E =
1 11 111
4 44 444
7 77 777
2 22 222
5 55 555
8 88 888
3 33 333
6 66 666
9 99 999
0 Comments
See Also
Categories
Find more on Resizing and Reshaping 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!