Find maximum of each cell array element efficiently

We have foe example a 3x5 cell array where each element is a matrix. Can we find the maximum of each cell element, i.e, a matrix, and store the corresponding value in a new 3x5 matrix? All this without for loops. Bellow there is the naive way.


a = rand(5,6);
b = rand(7,6);
c = rand(7,9);
d = rand(27,19);
CellArray = cell(2,2);

MaxResults = nan(size(CellArray));
for i=1:numel(size(CellArray))
    MaxResults(i) = max(max(CellArray{i})); 

Thank you.


Not guaranteed to be that much more efficient (until Matlab decides to multithread it), but you can use cellfun like this:

MaxResults = cellfun(@(x)max(x(:)), CellArray)

Need Your Help

Doctrine Query Builder ACOS function cannot be found

symfony doctrine-orm

I want to calculate distance in my custom repository class. The problem is that Doctrine throws exception while processing ACOS function:

Parallel between LMax Disruptor and Rx Framework concept?

java .net architecture concurrency reactive-programming

As I read here