How to extract max from a cell?

Hi, I'm dealing with image/video processing and I would like to extract the area of the biggest connected component for each frame. I have created a cell structure with the areas of each connected component in each frame. The problem is to create a proper "for loop" to store the values of max areas(from each frame) in an array. Then, I would like to do the same thing with mean(s) of pixels' intensity (for the biggest connected component). Any help will be extremely valuable. Thank you, Luisa

Answers (2)

Dear Luisa,
maybe the function cellfun does what you are looking for.
A = cell(3,1);
%Store with 3 matrices of different sizes
A{1} = magic(10);
A{2} = rand(20);
A{3} = ones(30);
%Extract the max of all cells
maxA = cellfun(@(X) max(max(X)), A)
Best, Sandro
% make some random cell for demo
A = cell(10,1) ;
for i = 1:10
A{i} = rand(randperm(10,1),1) ;
end
% get max using loop
iwant = zeros(length(A),1) ;
for i = 1:length(A)
iwant(i) = max(A{i}) ;
end
% use cellfun
m = cellfun(@max,A) ;
[iwant m]

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 17 May 2018

Answered:

on 17 May 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!