How to extract max from a cell?

16 次查看(过去 30 天)
luisa bertoli
luisa bertoli 2018-5-17
回答: KSSV 2018-5-17
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

回答(2 个)

Sandro Lecci
Sandro Lecci 2018-5-17
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

KSSV
KSSV 2018-5-17
% 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]

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by