如何创建矩阵矩阵? 我想创建一个n * m矩阵,每个元素是一个由三个元素组成的数组。我该怎么做?
感谢。
答案 0 :(得分:1)
例如
a =零(N,M,P)
P = 3
答案 1 :(得分:1)
最佳方式:谷歌更多关于Matlab's cell array
另一种方法:你可以创建一个3D(n-by-m-by-3)矩阵,即:m = zeros(n,m,3)
答案 2 :(得分:1)
您可以使用mat2cell
但我建议使用3D矩阵,因为其他答案建议
m = 5;
n = 4;
A = randi(50,n,m*3);
out = mat2cell(A,ones(n,1),repmat(3,m,1));
输出:
>> out
out =
[1x3 double] [1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double] [1x3 double]
[1x3 double] [1x3 double] [1x3 double] [1x3 double]
您可以使用{}
访问每个元素,如下所示:
>> out{1,1}
ans =
6 41 13
用于创建空单元格,
>> out = cell(m,n)
out =
[] [] [] []
[] [] [] []
[] [] [] []
[] [] [] []
[] [] [] []