フィルターのクリア

calculate mean each element in each cell in a cell array

2 ビュー (過去 30 日間)
HYZ
HYZ 2022 年 8 月 30 日
コメント済み: HYZ 2022 年 8 月 30 日
hi,
I have a cell
A = {[1,2,3, 4] [5,6,7,8] [9,10,11,12] ; [4,3,2,1] [8,7,6,5] [12,11,10,9]}.
I wanted to average each element. the result cell array will be B = {[2.5 2.5 2.5 2.5] [6.5 6.5 6.5 6.5] [10.5 10.5 10.5 10.5]}.
Please suggest. thanks!

採用された回答

David Hill
David Hill 2022 年 8 月 30 日
A = {[1,2,3, 4] [5,6,7,8] [9,10,11,12] ; [4,3,2,1] [8,7,6,5] [12,11,10,9]};
B=mat2cell(mean(cell2mat(A)),1,length(A{1,1})*ones(1,size(A,2)))
B = 1×3 cell array
{[2.5000 2.5000 2.5000 2.5000]} {[6.5000 6.5000 6.5000 6.5000]} {[10.5000 10.5000 10.5000 10.5000]}
  1 件のコメント
HYZ
HYZ 2022 年 8 月 30 日
if the cell array is 1x3x2 (made up of two A cell arrays, can I use loop to get B (1x3x2) array to average in the same way? thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by