How to extract max from a cell?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Sandro Lecci
am 17 Mai 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 Kommentare
KSSV
am 17 Mai 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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!