How to find the center of matrix

26 ビュー (過去 30 日間)
Mingde
Mingde 2022 年 5 月 25 日
コメント済み: Image Analyst 2022 年 5 月 27 日
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 件のコメント
Mingde
Mingde 2022 年 5 月 25 日
Center of force and center of mass are the same.
Here is the sample data(CSV file) for measuring the center of force.
DGM
DGM 2022 年 5 月 25 日
Your data is 14925x10, with periodic rows of NaN every 17 rows. It's not clear what this data represents or how the NaNs should be treated. Is this a contiguous 2D region? Multiple independent 2D regions? A 3D volume? Are the NaN rows merely delimiters/breaks to be discarded, or do they have numerical meaning? If they are to be kept, how should they be handled?

サインインしてコメントする。

採用された回答

DGM
DGM 2022 年 5 月 25 日
編集済み: DGM 2022 年 5 月 25 日
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(:))
Ft = 20
% coordinates of F centroid
cy = sum((1:size(F,1)).'.*sum(F,2))/Ft
cy = 3
cx = sum((1:size(F,2)).*sum(F,1))/Ft
cx = 3
% visualize the result
imshow(F,[]); hold on
plot(cx,cy,'*','markersize',20)
  5 件のコメント
Mingde
Mingde 2022 年 5 月 27 日
Thank you for your answer.
Image Analyst
Image Analyst 2022 年 5 月 27 日
You never answered his questions about whether your multiple regions are to be treated as a single region, or whether you want the location of the centroid for each region individually. But he gave you the centroid of all regions as if they were a single region and you accepted so I guess that's what you wanted.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 5 月 26 日
Did you try
data(isnan(data)) = 0;
mask = data ~= 0;
props = regionprops('table', mask, data, 'WeightedCentroid');
  1 件のコメント
Mingde
Mingde 2022 年 5 月 27 日
Thank you for your answer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by