Mean Value of Cell array having uneven vector

Hi, I have a cell array of dimension mxn, each element of the cell is a vector of 1xp but p is not of same size. I want to create an array of mxp containing the mean value of each element (with index p) across all the cell element (index n). Can someone help me in this regard.
Thank You
Tukaram

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 30 日

0 投票

An alternative approach
C = {1, [1 2 3]; [2 3], [3 5]};
mp = max(cellfun(@numel, C(:)));
C = cellfun(@(x) {[x nan(1, mp-numel(x))]}, C);
M = cell2mat(arrayfun(@(i) {nanmean(cellfun(@(x) x(i), C), 2)}, 1:mp));
Result
>> M
M =
1.0000 2.0000 3.0000
2.5000 4.0000 NaN

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by