Filter löschen
Filter löschen

compute centroid of a matrix

69 Ansichten (letzte 30 Tage)
Elysi Cochin
Elysi Cochin am 9 Jun. 2014
Beantwortet: David Lieberman am 10 Aug. 2017
how to compute centroid of a matrix? is it possible?

Akzeptierte Antwort

Matt J
Matt J am 9 Jun. 2014
Bearbeitet: Matt J am 9 Jun. 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(:))]

Weitere Antworten (1)

David Lieberman
David Lieberman am 10 Aug. 2017
x = sum(sum(matrix).*(1:size(matrix,2)))/sum(sum(matrix))
y is computed similarly

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by