您可以通过多种不同的方式来做到这一点。一种选择是使用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提取数值数据。