Split a matrix into separate matrices and find centroid of each smaller matrix

16 ビュー (過去 30 日間)
Meg Cullen
Meg Cullen 2019 年 5 月 16 日
編集済み: Meg Cullen 2019 年 5 月 17 日
I want to split a Nx2 matrix into k number of matrices, find the centroid of each matrix and then put the centroids into another matrix.
For example for A = 50x2 matrix and k = 10
The 10 smaller matrices will be 5x2 each.
The matrix containing the centroids of 10 matrices will be 10x2
[ Centroid of a Nx2 matix is a point equidistant from all points in the matrix when plotted. Each of the matrix rows are x&y axis values. For a collection of points x1,x2,x3,.....xn & y1,y2,y3,.....yn.
Centroid(x',y')
x' = (x1+x2+x3+......+xn) /n
y' = (y1+y2+y3+......+yn) /n ]
How to constuct this code?
  2 件のコメント
Kevin Phung
Kevin Phung 2019 年 5 月 16 日
編集済み: Kevin Phung 2019 年 5 月 16 日
what have you tried? and what do you mean by centroid?
If youre finding a centroid for 10 matrices, how is the collection of centroids a 10x2?
Meg Cullen
Meg Cullen 2019 年 5 月 17 日
Centroid is a point equidistant from all points in the matrix when plotted. Each of the rows are x&y axis values. For a collection of points x1,x2,x3,.....xn & y1,y2,y3,.....yn.
Centroid(x',y')
x' = (x1+x2+x3+......+xn) /n
y' = (y1+y2+y3+......+yn) /n

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

採用された回答

KSSV
KSSV 2019 年 5 月 17 日
A = rand(50,2) ;
k = 10 ;
[r,c] = size(A);
nlay = r/k ;
out = permute(reshape(A',[c,r/nlay,nlay]),[2,1,3]);
% Get mean
M = squeeze(mean(out))'
  3 件のコメント
KSSV
KSSV 2019 年 5 月 17 日
What is difference between:
x' = (x1+x2+x3+......+xn) /n
y' = (y1+y2+y3+......+yn) /n
and mean?
Meg Cullen
Meg Cullen 2019 年 5 月 17 日
編集済み: Meg Cullen 2019 年 5 月 17 日
sorry.....its my mistake.... I used a incorret matrix to test the code. I am new at using Matlab.
Its working correctly. Thank you very much.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by