> I want to segment and export a certain number of slices along Z axis
The following two demos use the attached file teatpotOut.ply which is within a zip file since we cannot attach ply files. The two demos show two different interpretations of the question.
Interpretation 1: segmenting specific z-values
Read-in the ply file
teapotOut.ply = unzip('teapotOut.zip');
ptCloud = pcread('teapotOut.ply');
List z-values of interest
This demo selects every 500-th unique z-value resulting in 11 z-values.
zUnq = unique(ptCloud.Location(:,3));
zSlices = zUnq(1:500:nzUnq);
Extract all point coordinates that belong to the selected z-values
zIdx = ismember(ptCloud.Location(:,3),zSlices);
ptCloudSegmented = ptCloud.Location(zIdx,:);
Plot results
Interpretation 2: segmenting a range of z-values
Read-in the ply file
teapotOut.ply = unzip('teapotOut.zip');
ptCloud = pcread('teapotOut.ply');
List a range of z-values to include in extraction
This demo selects all z-values between 0.8-1.2, inclusive.
Extract all point coordinates that belong to the selected z-values
zIdx = ptCloud.Location(:,3)>=zLim(1) & ptCloud.Location(:,3)<=zLim(2);
ptCloudSegmented = ptCloud.Location(zIdx,:);
Plot results