Dividing the point cloud in 10x10 ways
Show older comments
Hello, my problem is that I am working on a 3-dimensional point cloud like in the title and I want to split it into 10x10 pieces over x and y. As I am new to Matlab, I didn't know how to do this for now.

Answers (2)
Load built-in pointcloud data and look at the pointcloud object pc
load('xyzPoints');
pc = pointCloud(xyzPoints)
X/Y/ZLimits are the range of x,y,z points. Create a 10x10 grid within the x and y ranges. The bounds are defined in xyBounds (nx2).
[x,y] = meshgrid(linspace(pc.XLimits(1), pc.XLimits(2), 10), ...
linspace(pc.YLimits(1), pc.YLimits(2), 10));
xyBounds = [x(:),y(:)]
Use indexing to access a particular section of points.
Get all points within the bin #n
- pc.Location are all [x,y,z] coordinates.
- idx is a logical vector identifying points in pc.Location that are in the bin
- section are the [x,y,z] coordinates within the bin.
n = 50; % 50th bin xyBounds(n,:)
xIdx = pc.Location(:,1) >= xyBounds(n,1) & pc.Location(:,1) < xyBounds(n+1,1);
yIdx = pc.Location(:,2) >= xyBounds(n+1,2) & pc.Location(:,2) < xyBounds(n,2);
idx = xIdx & yIdx;
section = pc.Location(idx,:)
Some bins will not have any points and will return a 0x3 empty matrix.
11 Comments
Ahmet Selim Arslan
on 29 Mar 2021
Adam Danz
on 29 Mar 2021
Good news: it's not your fault! :)
Minutes after I submitted my answer I edited it to fix that error but it looks like you copied the code quickly after I submitted the original answer and before I fixed it. - Sorry about that.
Please see the updated version of the answer.
Ahmet Selim Arslan
on 29 Mar 2021
Since there are no axis labels and since I do not know the viewing angle, I can only assume that the vertical axis is Z and the longer of the two other axes is y. In that case, it looks like you have a slice along the x-axis but not along the y-axis. Was that your goal? I interpreted your questions as forming a 2D grid along the xy plane which would result in a column of points but in your image I see a slice of points.
Ahmet Selim Arslan
on 29 Mar 2021
Most of my answer still applies to that goal. Some changes:
pc = pointCloud(. . .);
xEdges= linspace(pc.XLimits(1), pc.XLimits(2), 11);
yEdges = linspace(pc.YLimits(1), pc.YLimits(2), 11);
xGroup = discretize(pc.Location(:,1),xEdges); %puts all x coordinates into groups
yGroup = discretize(pc.Location(:,2),yEdges); %puts all y coordinates into groups
[xyGroups, ~, groupID] = unique([xGroup, yGroup], 'row');
xyGroups are all unique (x,y) groups. size(xyGroups,1) is the number of groups.
groupID is the group ID for each point. groupID(i) is the grid group for point pc.Location(i,:) and blongs to group groupID(i,:) which has x and y edges defined by xEdges(groupID(i,1)+[0,1]) and yEdges(groupID(i,2)+[0,1]).
Note: this was written on the fly and not tested. If you run into errors with this try to troubleshoot it before reporting the error.
Adam Danz
on 31 Mar 2021
@Ahmet Selim Arslan please take a few seconds to accept answers to your questions by pressing the blue [accept this answer] button. Here are links to you questions - none of which you've accepted answers to
Ahmet Selim Arslan
on 7 Apr 2021
Adam Danz
on 7 Apr 2021
That's great to hear (I was trying to improve myself in coding).
All of your questions have reasonable answers but you've never accepted any of them. That makes it unclear whether those solutions worked for you or not.
About plotting the groups of points, that's a different question than what's asked here. Wouldn't they be plotted the same way you plotted the original pointcloud?
Ahmet Selim Arslan
on 10 Apr 2021
Ahmet Selim Arslan
on 11 Apr 2021
darova
on 24 Mar 2021
see this example
clc,clear
x = rand(10,10,10);
y = rand(10,10,10);
z = rand(10,10,10);
ix = round(5*x);
iy = round(5*y);
plot3(x(:),y(:),z(:),'.b');
hold on
h = plot3(0,0,0,'or');
hold off
view(15,60)
for i = 1:5
for j = 1:5
ind = (i==ix) & (j==iy);
set(h,'xdata',x(ind))
set(h,'ydata',y(ind))
set(h,'zdata',z(ind))
pause(0.2)
end
end

4 Comments
Ahmet Selim Arslan
on 28 Mar 2021
Ahmet Selim Arslan
on 28 Mar 2021
darova
on 29 Mar 2021
Can you explain how exactly you want to divide the region?
Ahmet Selim Arslan
on 29 Mar 2021
Categories
Find more on Point Cloud Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


