compute centroid of a matrix

31 views (last 30 days)
Elysi Cochin
Elysi Cochin on 9 Jun 2014
Answered: David Lieberman on 10 Aug 2017
how to compute centroid of a matrix? is it possible?

Accepted Answer

Matt J
Matt J on 9 Jun 2014
Edited: Matt J on 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(:))]

More Answers (1)

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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!