Search code examples
matlabpoint-clouds

Saving Multiple Objects of Class (point Clouds)


I need to save multiple point clouds generated in a loop. I tried to save them in an array which returns an error:

Array formation and parentheses-style indexing with objects of class 'pointCloud' is not allowed.

while i<=N
.
.
[imageDepth, pointCld] = getPointCloud(cp, maxDistance);
 imgDepthAll(:,:,i) = imageDepth;
 pointCldAll(:,:,i) = pointCld;
.
.
 i = i+1;
end

How can I fix this? Thank you very much.


Solution

  • The second output (pointCld) is a PointCloud2 object that apparently does not support being placed into an array. Because of this, you would want to place them into a cell array.

    pointCldAll{k} = pointCld;
    

    If you want the actual XYZ or RGB data from this object, you'll want to access it using the following methods and then you could store them in a normal array.

    xyz = readXYZ(pointCld)
    rgb = readRGB(pointCld)
    

    Or fetch the Location property and store that.

    loc = pointCld.Location