简体   繁体   中英

How do I find the maximum of each dimension in a cell array of matrices?

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.

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)

我想您正在寻找:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM