Centroid of two arrays

1 次查看(过去 30 天)
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

采纳的回答

Adam Danz
Adam Danz 2021-1-14
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 个评论
Adam Danz
Adam Danz 2021-1-14
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 2021-1-14
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?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by