简体   繁体   English

如何在矩阵的单元格数组中找到每个维度的最大值?

[英]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. 我得到了A由不同大小的矩阵组成的单元格数组A 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: 例如, A上面的示例A的此操作的预期输出应为:

[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. 这是因为通过检查第一维,三个矩阵上的最大行数为16。类似地,三个矩阵上的最大列数为14。

My original answer returned the maximum element of the cell. 我的原始答案返回了单元格的最大元素。 Now including your comments the right code: 现在在注释中添加正确的代码:

knedlsepp basically got it. knedlsepp基本上得到了它。 Minor improvement in performance: 性能略有改善:

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

我想您正在寻找:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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