How to convert centroid values to array

4 views (last 30 days)
Ad
Ad on 25 Apr 2017
Answered: Image Analyst on 7 May 2017
distance=l(1).centroid; %works fine
1 2
1 12.79 9.970
*while performing loop I am getting an error of array mismatch.(I think centroid has two values but I am trying to assign it to single array.)
for i=1:N
distance(i)=l(i).Centroid % getting an error
end
centroid values
[12.7956777996070,9.97053045186637]
[12.3260393873085,45.6477024070019]
[12.2386934673366,63.8693467336681]
[17.4170755642790,86.2463199214916]
[13.3798076923078,118.569711538463]

Answers (1)

Image Analyst
Image Analyst on 7 May 2017
I wouldn't call it l - It's probably the single worst name, other than O that you could use. I looks too much like 1(one) and l (lower case L). Call it props since it comes from regionprops(). So
allCentroids = [props.Centroid];
xCentroids = allCentroids(1:2:end);
yCentroids = allCentroids(2:2:end);

Community Treasure Hunt

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

Start Hunting!