Centroid of two arrays

1 view (last 30 days)
Ayesha Zaka
Ayesha Zaka on 14 Jan 2021
Commented: Image Analyst on 14 Jan 2021
Hi,
I have a code that computes the centroids of two arrays as:
for ij=1:size(v1,1)
cent(ij)=centroid(v2,v1(ij,:));
end
What is the physical meaning of doing this operation? The help of 'centroid' explains the calculation of centroids for polygon shapes and I can not understand how the data in the two arrays is affected by centroid through that. The attached .mat file contains the two variables v1 and v2

Accepted Answer

Adam Danz
Adam Danz on 14 Jan 2021
I agree that the documentation on describing the inputs could be more specific. Look at the examples in the documentation for centroid and it may fill in the gaps. Plotting the results may help to interpret the results, too.
ij = 1; % sample the first iteration
plot(v2, v1(ij,:), 'ko')
ps = polyshape(v2,v1(ij,:));
[xCnt, yCnt] = centroid(ps);
hold on
plot(xCnt, yCnt, 'rx', 'MarkerSize', 15)
% Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been
% modified to create a well-defined polyshape.
% > In polyshape/checkAndSimplify (line 517)
% In polyshape (line 175)
  7 Comments
Adam Danz
Adam Danz on 14 Jan 2021
Ahhhh... that's what I thought. If the differences between the built-in function and the 3rd party function are very small, it might just be roundoff error but if you're unsure which to use and you're sure that the built-in version does what you want, use that one.
Image Analyst
Image Analyst on 14 Jan 2021
So which centroid function do you want to use?
Sounds like you don't want the built-in one that works on polygons and that you're wondering how/why your colleague's code works.
But what we'd really like to know is, given the x and y vectors you attached (I'm assuming that's what Adam plotted), what do you expect to get from it and why? The "centroid" of a Gaussian, like the red cross Adam plotted, doesn't seem useful but maybe I'm wrong. What are you going to do next, assuming you can get whatever it is you need?

Sign in to comment.

More Answers (0)

Categories

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