我想按照SOF问题的建议,使用dlmread
函数从字符串end_header的下一行开始,将PLY文件读取到MATLAB矩阵。样本PLY文件被赋予here。目前,起始行的硬编码如下,但它不适合,因为PLY文件中的标题行数可能会发生变化。
data = dlmread(fileName, ' ', 14, 0);
答案 0 :(得分:1)
你可以通过不同的方式实现这一目标。一种选择是使用textscan
来读取整个文件以及strfind
和find
的混合,以确定包含'end_header'
的行
filename = 'testPly.ply';
fid = fopen(filename);
data = textscan(fid, '%s', 'delimiter', '\n');
idx = find(cellfun(@isempty, strfind(data{1}, 'end_header')) == 0);
fclose(fid);
然后您可以使用dlmread
作为
data = dlmread(filename, ' ', idx, 0);
或根据我的previous answer提取数字数据。
另一种方法,如果您的文件在'end_header'
之后包含大量数据可能会更好,但在您使用fgets
找到'end_header'
之前读取每一行之前不会很多
idx = 1;
fid = fopen(filename, 'r');
while isempty(strfind(fgets(fid), 'end_header'))
idx = idx + 1;
end
fclose(fid);
然后使用dlmread
或根据我的previous answer提取数字数据。