Main Content


Write 3-D surface mesh into STL or PLY file

Since R2022b



    writeSurfaceMesh(mesh,fileName) writes the surface mesh mesh into an STL or PLY file with the specified filename.

    writeSurfaceMesh(mesh,fileName,Encoding=enc) additionally specifies the encoding type as "ascii" or "binary".


    collapse all

    Define mesh vertices and faces for a surface mesh.

    vertices = [0 0 0; 0 0 1; 0 1 1; 0 0 2; 1 0.5 1];
    faces = [1 2 3; 2 3 4; 2 3 5];

    Create and display the surface mesh.

    mesh = surfaceMesh(vertices,faces);

    Figure contains an object of type images.ui.graphics3d.viewer3d.

    Write the surface mesh data into an STL file.


    Write the surface mesh data into a PLY file.


    Input Arguments

    collapse all

    Surface mesh to write, specified as a surfaceMesh object.

    Filename to write surface mesh data to, specified as a character vector or string scalar. You must specify the .stl or .ply extension along with the filename. If a file of specified name already exists, it must have write permissions.

    Encoding type in which to write surface mesh data to the file, specified as "ascii" or "binary".

    Data Types: char | string


    You cannot write these attributes into an STL file.

    • Vertex normals

    • Vertex colors

    • Face colors

    You cannot write face normals and face colors into a PLY file.

    Version History

    Introduced in R2022b