Reading ply file into my matlab code
Posted: Mon Jun 03, 2019 10:49 pm
Hello, I have a point cloud which I then used to create a mesh on Cloud Compare. This worked out very well. The issue is that I then need to read in this ply file into a matlab code. This code works for other ply files, however when I try to use the file that I need to use, I obtain the following error:
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 3) ==> by CloudCompare!\n
I have attached the matlab function below, any help would be greatly appreciated.
Thank you
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;
Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 3) ==> by CloudCompare!\n
I have attached the matlab function below, any help would be greatly appreciated.
Thank you
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;