Main Content

readField

(To be removed) Read point cloud data based on field name

readField will be removed in a future release. Use rosReadField instead. For more information, see ROS Message Structure Functions.

Description

fielddata = readField(pcloud,fieldname) reads the point field from the PointCloud2 object, pcloud, specified by fieldname and returns it in fielddata. If fieldname does not exist, the function displays an error. To preserve the structure of the point cloud data, see Preserving Point Cloud Structure.

example

Examples

collapse all

Load sample ROS messages including a ROS point cloud message, ptcloud.

exampleHelperROSLoadMessages

Read the 'x' field name available on the point cloud message.

x = readField(ptcloud,'x');

Input Arguments

collapse all

Point cloud, specified as a PointCloud2 object handle for a sensor_msgs/PointCloud2 ROS message.

Field name of point cloud data, specified as a string scalar or character vector. This string must match the field name exactly. If fieldname does not exist, the function displays an error.

Output Arguments

collapse all

List of field values from point cloud, returned as a matrix. Each row of the matrix is a point cloud reading, where n is the number of points and c is the number of values for each point. If the point cloud object being read has the PreserveStructureOnRead property set to true, the points are returned as an h-by-w-by-c matrix. For more information, see Preserving Point Cloud Structure.

Tips

Point cloud data can be organized in either 1-D lists or in 2-D image styles. 2-D image styles usually come from depth sensors or stereo cameras. The input PointCloud2 object contains a PreserveStructureOnRead property that is either true or false (default). Suppose you set the property to true.

pcloud.PreserveStructureOnRead = true;

Now calling any read functions (readXYZ,readRGB, or readField) preserves the organizational structure of the point cloud. When you preserve the structure, the output matrices are of size m-by-n-by-d, where m is the height, n is the width, and d is the number of return values for each point. Otherwise, all points are returned as a x-by-d list. This structure can be preserved only if the point cloud is organized.

Version History

Introduced in R2019b

collapse all

R2021a: ROS Message Structure Functions

You can now create messages as structures with fields matching the message object properties. Using structures typically improves performance of creating, updating, and using ROS messages, but message fields are no longer validated when set. Message types and corresponding field values from the structures are validated when sent across the network.

To support message structures as inputs, new functions that operate on specialized ROS messages have been provided. These new functions are based on the existing object functions of message objects, but support ROS and ROS 2 message structures as inputs instead of message objects.

The object functions will be removed in a future release.

Message TypesObject Function NameNew Function Name

Image

CompressedImage

readImage

writeImage

rosReadImage

rosWriteImage

LaserScan

readCartesian

readScanAngles

lidarScan

plot

rosReadCartesian

rosReadScanAngles

rosReadLidarScan

rosPlot

PointCloud2

apply

readXYZ

readRGB

readAllFieldNames

readField

scatter3

rosApplyTransform

rosReadXYZ

rosReadRGB

rosReadAllFieldNames

rosReadField

rosPlot

QuaternionreadQuaternion

rosReadQuaternion

OccupancyGrid

readBinaryOccupanyGrid

readOccupancyGrid

writeBinaryOccupanyGrid

writeOccupanyGrid

rosReadOccupancyGrid

rosReadBinaryOccupancyGrid

rosReadOccupancyGrid

rosWriteBinaryOccupancyGrid

rosWriteOccupancyGrid

OctomapreadOccupancyMap3D

rosReadOccupancyMap3D

PointStamped

PoseStamped

QuaternionStamped

Vector3Stamped

TransformStamped

apply

rosApplyTransform

All messagesshowdetails

rosShowDetails