创建一个3D矩阵
问题描述:
如何在MATLAB中定义3D矩阵?
How can I define a 3D matrix in MATLAB?
例如尺寸为(8 x 4 x 20)的矩阵,还是将第3维添加到现有的2D矩阵中?
For example a matrix of size (8 x 4 x 20) or add a 3rd dimension to an existing 2D matrix?
答
创建3D矩阵
A = zeros(20, 10, 3); %# Creates a 20x10x3 matrix
将第三维添加到矩阵
B = zeros(4,4);
C = zeros(size(B,1), size(B,2), 4); %# New matrix with B's size, and 3rd dimension of size 4
C(:,:,1) = B; %# Copy the content of B into C's first set of values
零点只是制作新矩阵的一种方法.对于3D矩阵,另一个可能是A(1:20,1:10,1:3) = 0
.要确认矩阵的大小,可以运行:size(A)
给出20 10 3
.
zeros is just one way of making a new matrix. Another could be A(1:20,1:10,1:3) = 0
for a 3D matrix. To confirm the size of your matrices you can run: size(A)
which gives 20 10 3
.
矩阵的维数没有明确的限制.
There is no explicit bound on the number of dimensions a matrix may have.