How can I assign a unique label to all points lying inside a single sub-region of divided 3D space?

3 ビュー (過去 30 日間)
Suppose I have a 3D space. I have divided it using grids with X = 0:2:6, Y = 0:1:6 and Z = 0:3:9. So that now I have 54 small 3D regions. Few points are scattered in the entire 3D region. I have to find how many points are lying inside individual small region. Also I have to assign a label for all points in each region, e.g. All points in region 1 will have label 1, all in region 2 will be label 2, so on. I have added the picture for the reference.
Is there any direct function in matlab to find a solution for this problem ? Using if else conditions would be complex if the number of grids and dimensions increases. Is there any idea or hint ?
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 6 月 25 日
Please recheck Z=0:2:10 . Your image is Z=0:3:9 . With 0:2:10 you would have 90 bins.
Varun Pai
Varun Pai 2018 年 6 月 25 日
Thank u for the observation. It is Z =0:3:9 actually.

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

回答 (2 件)

KSSV
KSSV 2018 年 6 月 25 日
Go for logical indexing......If (X,y,z) are you points. To get the points lying between (x1,y1,z1) and (x2,y2,z2) ;
idx = (x>x1 & x<=x2) & (y>y1 & y<=y2) & (z>z1 & z<=z2) ;
Initilize your label matrix and fill the value you want for the above idx.
  2 件のコメント
Varun Pai
Varun Pai 2018 年 6 月 25 日
Logical indexing would be difficult if the dimension and grid size gets increased. The more number of grids, the more conditions we may have to write
KSSV
KSSV 2018 年 6 月 25 日
Generally logical indexing would be fast.

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


Walter Roberson
Walter Roberson 2018 年 6 月 25 日
Let the coordinates of the points be stored in x, y, z
nx = 3; ny = 6; nz = 3;
xb = floor(x/2)+1;
yb = floor(y)+1;
zb = floor(z/3)+1;
counts = accumarray([xb(:), yb(:), zb(:)], 1, [nx, ny, nz]);
labels = sub2ind([nx, ny, nz], xb, yb, zb);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by