# Using for loop for cell array

3 views (last 30 days)
Amir Azadeh Ranjbar on 3 Dec 2021
clc;clear;close all
figure;imshow(bw);title('orginal image')
[B,~,N]=bwboundaries(bw);
obj1=B{1}; x1=obj1(:,2); y1=obj1(:,1);
area1=polyarea(x1,y1)
obj2=B{2}; x2=obj2(:,2); y2=obj2(:,1);
area2=polyarea(x2,y2)
obj3=B{3}; x3=obj3(:,2); y3=obj3(:,1);
area3=polyarea(x3,y3)
AREA=[area1 area2 area3];
[Max,name]=max(AREA(:));
MAX=B{name};
hold on
plot(MAX(:,2),MAX(:,1),"Color","r","LineWidth",2);
title(['max sphere = ',num2str(Max)])
% I want insert for loop for obj 1:3
% Thanks
Amir Azadeh Ranjbar on 3 Dec 2021
I want insert for loop for obj 1:3
for more objects if exist
Thanks

Voss on 4 Dec 2021
clc;clear;close all
figure;imshow(bw);title('orginal image')
[B,~,N]=bwboundaries(bw);
nB = numel(B);
AREA = zeros(1,nB);
for i = 1:nB
obj = B{i};
x = obj(:,2);
y = obj(:,1);
area = polyarea(x,y);
AREA(i) = area;
end
[Max,name]=max(AREA(:));
MAX=B{name};
hold on
plot(MAX(:,2),MAX(:,1),"Color","r","LineWidth",2);
title(['max sphere = ',num2str(Max)])
Amir Azadeh Ranjbar on 4 Dec 2021
Its Working well
Thanks

### Categories

Find more on Structures 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!

Translated by