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
  1 件のコメント
Chris Dan
Chris Dan 2020 年 6 月 9 日
thanks :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by