Cernter of gravity.

2 ビュー (過去 30 日間)
Patrick Brandt
Patrick Brandt 2021 年 4 月 20 日
編集済み: Jan 2021 年 4 月 21 日
Hi, I got a 58x22x122 matrix and have to calculate the center of gravity in every single layer for its own. But I have no clue how to do it, please give advice if you know.
Thanks alot

採用された回答

Adam Danz
Adam Danz 2021 年 4 月 20 日
Learn about Center of Mass equations here

その他の回答 (1 件)

Jan
Jan 2021 年 4 月 20 日
編集済み: Jan 2021 年 4 月 21 日
I assume you mean the center of mass. A matrix is an rectangular set of numbers. So should we assume, that the values of the matrix are the local weights?
m = 58;
n = 22;
X = rand(m, n);
R = [0, 0];
for i1 = 1:m
for i2 = 1:n
R = R + X(i1, i2) * [i1, i2];
end
end
R = R / sum(X, 'all') % Center of mass, if X(i1,i2) is the "mass"
More Matlab'ish without loops:
Rcol = sum(X .* (1:m).', 'all') / sum(X, 'all')
Rrow = sum(X .* (1:n), 'all') / sum(X, 'all')
Now create a loop and set X to each "layer" (however this is defined) of your input data.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by