MATLAB: Mean Value of Cell array having uneven vector

cell arraysmean

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

Best Answer

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