How to construct a 3x9 matrix E from a 3x3x3 matrix D, where D(x,y,:) is the column of E?

4 次查看(过去 30 天)
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.

回答(1 个)

Image Analyst
Image Analyst 2021-10-8
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

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by