Centroid of two arrays

1 visualización (últimos 30 días)
Ayesha Zaka
Ayesha Zaka el 14 de En. de 2021
Comentada: Image Analyst el 14 de En. de 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

Respuesta aceptada

Adam Danz
Adam Danz el 14 de En. de 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 comentarios
Adam Danz
Adam Danz el 14 de En. de 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 el 14 de En. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by