【发布时间】:2017-09-23 19:58:16
【问题描述】:
我有一个恒定的二维双矩阵mat1。我还有一个 2D 单元格数组 mat2,其中每个单元格都包含一个 2D 或 3D 双矩阵。这些双精度矩阵的行数和列数与mat1 相同。我需要将mat1 与mat2 内的每个双矩阵的每个切片点乘(。*)。结果需要是另一个元胞数组results,其大小与mat2 相同,其中包含的双精度矩阵的大小必须等于mat2 的双精度矩阵。
这是我生成 mat1 和 mat2 的代码,用于说明目的。我在应该发生乘法的地方挣扎。
rowCells = 5;
colCells = 3;
rowTimeSeries = 300;
colTimeSeries = 5;
slices = [1;10];
% Create 2D double matrix
mat1 = rand(rowTimeSeries, colTimeSeries);
% Create 2D cell matrix comprisiong 2D and/or 3D double matrices
mat2 = cell(rowCells,colCells);
for c = 1:colCells
for r = 1:rowCells
slice = randsample(slices, 1, true);
mat2{r,c} = rand(rowTimeSeries, colTimeSeries, slice);
end
end
% Multiply (.*) mat1 with mat2 (every slice)
results = cell(rowCells,colCells);
for c = 1:colCells
for r = 1:rowCells
results{r,c} = ... % I am struggling here!!!
end
end
【问题讨论】:
标签: matlab multidimensional-array cell-array multiplication