如何 return 包含给定列的最大值元素的单元格的索引

How to return the index of a cell which holds the largest valued element of a given column

假设我们有 Q 个单元格,每个单元格都有一个 N x M 数组。其中 Array{q}(n,m) 是第 q 个单元格第 m 列第 n 行中的元素。

我想找到每列中包含最大值元素的单元格的索引。

谁能推荐一个简单的方法来做到这一点?

我会将您的元胞数组串联成一个 3D 矩阵,然后使用 max 查找每列的最大值,然后使用 max 再次查找沿 third维度并使用max的第二个输出表示它属于哪个单元格

% Convert data into 3D array
condensed = cat(3, Q{:});

% Find the location in the maximum
[~, ind] = max(max(condensed, [], 1), [], 3);

举个例子:

Q = {[2 1; 
      4 0], ...

     [1 2; 
      3 1]};

[~, ind] = max(max(cat(3, Q{:}), [], 1), [], 3);
%   1   2