# How to find the center of matrix

41 views (last 30 days)

Show older comments

Dear all helper,

I want like to calculate the center of force in 2 point that I draw in the red color by using matlab.

Here is attech file of the csv data.

##### 3 Comments

DGM
on 25 May 2022

### Accepted Answer

DGM
on 25 May 2022

Edited: DGM
on 25 May 2022

This seems fairly straightforward.

% a test array

F = zeros(5);

F(2,2) = 10;

F(4,4) = 10;

% global sum of F

Ft = sum(F(:))

% coordinates of F centroid

cy = sum((1:size(F,1)).'.*sum(F,2))/Ft

cx = sum((1:size(F,2)).*sum(F,1))/Ft

% visualize the result

imshow(F,[]); hold on

plot(cx,cy,'*','markersize',20)

##### 5 Comments

Image Analyst
on 27 May 2022

### More Answers (1)

Image Analyst
on 26 May 2022

Did you try

data(isnan(data)) = 0;

mask = data ~= 0;

props = regionprops('table', mask, data, 'WeightedCentroid');

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!