Sum of all columns in a 3D cell array

조회 수: 4 (최근 30일)
Chris Dan
Chris Dan 2020년 6월 9일
댓글: Chris Dan 2020년 6월 9일
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