How do I find the maximum of each dimension in a c

2019-03-04 04:47发布

问题:

I am given a cell array A which consists of matrices of different sizes. For example, I could have a three element cell array where the dimensions for each element are:

A{1} -> 4 x 3
A{2} -> 16 x 4
A{3} -> 5 x 14

How would I traverse through the cell array and return the maximum for each dimension overall? For example, the expected output of this operation with the example A above should give:

[16 14]

This is because by examining the first dimension, the maximum number of rows over the three matrices is 16. Similarly, the maximum number of columns over the three matrices is 14.

回答1:

My original answer returned the maximum element of the cell. Now including your comments the right code:

knedlsepp basically got it. Minor improvement in performance:

[a(:,1),a(:,2)]=cellfun(@size,A);
max(a)


回答2:

I guess you are looking for:

max(cell2mat(cellfun(@size,A(:),'uni',0)),[],1)