How to extract max from a cell?
11 views (last 30 days)
Show older comments
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
0 Comments
Answers (2)
Sandro Lecci
on 17 May 2018
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
0 Comments
KSSV
on 17 May 2018
% 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]
0 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!