-1

Lets say we have Q cells, and each cell holds a N x M array. Where Array{q}(n,m) is the element in the nth row of the mth column of the qth cell.

I want to find the index of the cell that holds the greatest value element in each column.

Can anyone suggest a simple way to do this?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • Can you provide a small example of inputs and expected outputs? – Suever Dec 13 '16 at 14:09
  • How would you like your output formatted? I'm assuming you would like to have an array of length Q, where each cell holds a bit vector representing the indices of the row with the maximum value? – awerchniak Dec 13 '16 at 14:12

1 Answers1

1

I would concatenate your cell array into a 3D matrix, and then use max to find the maximum value of each column and then use max to again find the maximum value along the third dimension and use the second output of max to indicate which cell it belongs to

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

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

And as an example:

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

     [1 2; 
      3 1]};

[~, ind] = max(max(cat(3, Q{:}), [], 1), [], 3);
%   1   2
Suever
  • 64,497
  • 14
  • 82
  • 101
  • Genius, thank you. Here is what I ended up with: `condensed_cells=cat(3,cells{:}); [~, Index] = max(max(condensed_cells, [], 1), [], 3); Z=[]; for ix=1:col Z(:,ix)=cells{Index(1,ix)}(:,ix); end` Works perfect. – James Crawford Dec 13 '16 at 15:05