pcwrite
Write 3-D point cloud to PLY or PCD file
Description
pcwrite(
writes a ptCloud,filename,Encoding=encodingType)pointCloud object,
ptCloud, to a PLY file that is in the specified
format.
Examples
Load a point cloud into the workspace.
ptCloud = pcread("teapot.ply");
pcshow(ptCloud); 
pcwrite(ptCloud,"teapotOut",Encoding="binary");
Load a MAT file containing point cloud data into the workspace.
load("object3d.mat"); pcwrite(ptCloud,"object3d.pcd",Encoding="ascii"); pc = pcread("object3d.pcd"); pcshow(pc);

Input Arguments
File name, specified as a character vector or string scalar. The input file type must be a PLY or PCD format file.
For a PLY-file, the pcwrite function converts an organized
M-by-N-by-3 point cloud to an
unorganized M-by-3 format. It converts the format because
PLY files do not support organized point clouds. To preserve the organized
format, you can save the point cloud as a PCD-file.
If you do not specify the file name with an extension, the function writes the file in a
PLY-format. All NaN or Inf values
will be skipped when writing to a PLY file.
Object for storing point cloud, specified as a pointCloud object.
Encoding type for the output file, specified as
"ascii", "binary", or
"compressed". This table summarizes the valid and
default encoding types for PLY and PCD file formats.
| File Format | Valid Encodings |
|---|---|
| PLY |
|
| PCD |
|
To improve performance when writing large point clouds, use the
"compressed" or "binary" encoding
type.
Version History
Introduced in R2015aYou can now write a pointCloud object with a
Color property of data type uint8,
uint16, single, or
double to a PLY or PCD file. In previous releases, the valid
data types for the Color property depends on the file format
you write to.
Valid Color Data Types
| File Format | R2025b | R2026a |
|---|---|---|
| PLY |
|
|
| PCD |
|
|
The default value of the encodingType argument is now
"binary" for PLY files and "compressed"
for PCD files. Before R2026a, the default value is "ascii" for
both file formats.
In most cases, you do not need to make any changes to your code. However, if you
specifically want to write point cloud data to a PLY or PCD file with ASCII
encoding, you must specify the encodingType argument as
"ascii", as shown in this command:
pcwrite(ptCloud,"sample.ply",Encoding="ascii").
When you use the pcwrite function with the default encoding
type, the function shows improved performance. When you use the
pcread function to read a file generated by the
pcwrite function, the pcread function
also shows improved performance. The performance improvement increases as the number
of points stored in the point cloud increases. For example, writing and then reading
a point cloud using this code is about 17x and 11x faster, respectively, than in the
previous release.
function [tWrite,tRead] = timingTest % Create a large point cloud rng("default"); N = 1e6; % Number of points x = -50 + 100*rand(N,1); % range [-50, 50] y = -50 + 100*rand(N,1); % range [-50, 50] z = 10*rand(N,1); % range [0, 10] ptCloud = pointCloud([x y z]); % Measure execution time of the operations tWrite = timeit(@()pcwrite(ptCloud,"temp.ply")); tRead = timeit(@()pcread("temp.ply")); end
This table shows the approximate execution times required to write and read point cloud data to and from a PLY file.
| Release | pcwrite Execution Time | pcread Execution Time |
|---|---|---|
| R2025b | 2.19 s | 0.56 s |
| R2026a | 0.13 s | 0.05 s |
The code was timed on a Debian® 12, Intel®
Xeon® CPU W-2133 @ 3.60 GHz test system by calling the function
timingTest.
See Also
pointCloud | pcread | pcplayer | pcshow | pcmerge | pcfitplane | planeModel | pctransform | pcdownsample | pcdenoise | pcregistericp
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)