MATLAB Answers

0

Error using dlmread- mismatch between file and format character vector (reading a ply file)

Asked by Kaela Johnson on 3 Jun 2019
Latest activity Answered by Walter Roberson
on 4 Jun 2019
I am trying to read in a ply file to matlab using the following code:
function fv = read_ply2_ExampleData(fileName)
% this function reads a ply file (must be in text format)
% to calc. normals etc use calcMeshNormals
% Copyright : This code is written by Ajmal Saeed Mian {ajmal@csse.uwa.edu.au}
% Computer Science, The University of Western Australia. The code
% may be used, modified and distributed for research purposes with
% acknowledgement of the author and inclusion this copyright information.
% Modified by Vipin Vijayan.
x = dlmread(fileName, ' ', [4 2 4 2]);
y = dlmread(fileName, ' ', [15 2 15 2]);
header = 18; %starting by row=0, the first row of data to be read starts here
vertex = dlmread(fileName, ' ', [header 0 x+(header-1) 9]);
poly = dlmread(fileName, ' ', [x+header 0 x+(header-1)+y 3]);
poly(:,1) = [];
poly = poly + 1;
fv.vertices = vertex;
fv.faces = poly;
I obtain the following error:
Error using dlmread
Mismatch between file and format character vector. Trouble reading 'Numeric' field from file (row number 1, field number 3) ==> by CloudCompare!\n
I have been able to read in other ply files using this code, I am not sure what I am missing this time. The ply file is a large point cloud ( about 6 000 000 points) that I converted to a ply file using CloudCompare.

  0 Comments

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 4 Jun 2019
 Accepted Answer

Your ply file contains a comment in an unexpected place. If you look at the file in the place it contains "by CloudCompare" a number is expected. Possibly the code is expecting that the line ends at that point and that the next line starts with a number

  0 Comments

Sign in to comment.


Answer by Sean de Wolski
on 3 Jun 2019

Why not just use pcread?

  1 Comment

Thanks for the reply! I need the 3d coordinates of the vertices, and the faces of the mesh contained in the ply file, to then make a tree structure out of the vertices and faces for mesh intersection purposes. I created this ply file from a point cloud for that purpose.

Sign in to comment.