Using for loop for cell array

1 次查看(过去 30 天)
clc;clear;close all
bw = rgb2gray(imread('image_3.png'));
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

采纳的回答

Voss
Voss 2021-12-4
clc;clear;close all
bw = rgb2gray(imread('image_3.png'));
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)])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Behavior and Psychophysics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by