Sum of all columns in a 3D cell array

4 次查看(过去 30 天)
Hello,
I have a cell array by the name phi_z = {301x51x3}
I want to take a sum of all its columns in a single slice, so it would become phi_z = {301x1x3}. I have been reading the documentation
but I could not find it.
after wards, I would convert the cell array to double array.
does anyone know?
phi_z = cell(301,51,3);
out=cell2mat(phi_z)
A = sum(out,2)
  2 个评论
David Hill
David Hill 2020-6-9
I am confused. What is in each cell element? Or do you just have a 301x51x3 matrix in a single cell element?
Chris Dan
Chris Dan 2020-6-9
each cell element has a value of 1, each cell element is not a matrix, it is just one value

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2020-6-9
Here are the inputs according to your description
pyi_z = num2cell(rand(301,51,3));
% Check size
size(pyi_z)
ans =
301 51 3
% look at first 10 values and check format
pyi_z(1:10)
ans =
1×10 cell array
Columns 1 through 5
{[0.50532]} {[0.7123]} {[0.72638]} {[0.74586]} {[0.62423]}
Columns 6 through 10
{[0.27062]} {[0.80714]} {[0.29222]} {[0.21049]} {[0.60563]}
Convert from cell to numeric array, compute sum of columns
% Convert to numeric array
pyi_zArray = cell2mat(pyi_z);
% Sum of columns
t = sum(pyi_zArray,2);
% Check size of output
size(t)
ans =
301 1 3

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by