Hopefully the video was clear. This should work for all structured 3D objects (NO point clouds). If you are a little more proficient with programming, you can save computing time and space with a more efficient FOR loop and removing the repeated nodes. The PLY file also allows you to store color and material data, which is something I am currently investigating.
All the geometries in the thumbnail were exported using the code in this video. If you want to learn how to generate 3D objects, check my playlist linked below.
Playlist: Structured 3D OBJECTS in MATLAB
https://youtube.com/playlist?list=PLALdklvvx2NLIL-UrL3BymSRbZ4mC23hk
Playlist: FILE FORMATS in MATLAB
https://youtube.com/playlist?list=PLALdklvvx2NK2P7cVOBRPFmsPB3lFnXp_
fprintf() documentation:
https://www.mathworks.com/help/matlab/ref/fprintf.html
fopen() documentation:
https://www.mathworks.com/help/matlab/ref/fopen.html
fclose() documentation:
https://www.mathworks.com/help/matlab/ref/fclose.html
reshape():
https://www.mathworks.com/help/matlab/ref/reshape.html
colon:
https://www.mathworks.com/help/matlab/ref/colon.html
Software: MATLAB 2020b