compute centroid of a matrix
69 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Elysi Cochin
le 9 Juin 2014
Réponse apportée : David Lieberman
le 10 Août 2017
how to compute centroid of a matrix? is it possible?
0 commentaires
Réponse acceptée
Matt J
le 9 Juin 2014
Modifié(e) : Matt J
le 9 Juin 2014
If you have the Image Processing Toolbox,
regionprops(true(size(matrix)), matrix, 'WeightedCentroid');
Otherwise,
matrix=matrix/sum(matrix(:));
[m,n]=size(matrix);
[I,J]=ndgrid(1:m,1:n);
centroid=[dot(I(:),matrix(:)), dot(J(:),matrix(:))]
0 commentaires
Plus de réponses (1)
David Lieberman
le 10 Août 2017
x = sum(sum(matrix).*(1:size(matrix,2)))/sum(sum(matrix))
y is computed similarly
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!