How to store data from every cycle in while a loop?

조회 수: 3 (최근 30일)
Francesco Belluccini
Francesco Belluccini 2021년 8월 3일
댓글: Francesco Belluccini 2021년 8월 3일
Hello,
i'm trying to extract point data from slices taken from a point cloud. ptCloudSegmented contains the x,y,z of every point of the slice.
I wrote this code:
ptCloud=pcread('1_no_OK.ply'); %this is the whole point cloud
zLim=[0,0.5]; %section interval
while zLim < ptCloud.ZLimits (2)
zIdx = ptCloud.Location(:,3)>=zLim(1) & ptCloud.Location(:,3)<=zLim(2);
ptCloudSegmented = ptCloud.Location(zIdx,:);
ptCloudSegmented = double(ptCloudSegmented); % this is what i'm trying to save into a matrix in every cycle
zLim=zLim+0.5;
end
The problem is that every time the cycle restarts the ptCloudSegmented is overwritten by the new section of points. So i'm trying to insert a structure containing more instances of ptCloudSegmented, added dynamically, but i red that using dynamic variables makes the code a bit unstable. There's a way to solve this issue? Thanks in advice

채택된 답변

KSSV
KSSV 2021년 8월 3일
ptCloud=pcread('1_no_OK.ply'); %this is the whole point cloud
zLim=[0,0.5]; %section interval
ptCloudSegmented = cell([],1) ;
count = 0 ;
while zLim < ptCloud.ZLimits (2)
count = count+1 ;
zIdx = ptCloud.Location(:,3)>=zLim(1) & ptCloud.Location(:,3)<=zLim(2);
ptCloudSegmented{count} = double(ptCloud.Location(zIdx,:));
zLim=zLim+0.5;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by