【问题标题】:Reading a PLY file from a specific string从特定字符串中读取 PLY 文件
【发布时间】:2015-10-31 21:08:52
【问题描述】:

我想按照SOF 问题中的建议,使用dlmread 函数从字符串end_header 的下一行开始将PLY 文件读取到MATLAB 矩阵中。样品层文件提供here。目前起始行硬编码如下,但由于PLY文件中的标题行数可能会发生变化,因此不适合。

data = dlmread(fileName, ' ', 14, 0);

【问题讨论】:

    标签: string performance matlab delimiter filereader


    【解决方案1】:

    您可以通过多种不同的方式来做到这一点。一种选择是使用textscan 读取整个文件并混合使用strfindfind 来确定包含'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提取数值数据。

    【讨论】:

      猜你喜欢
      • 2016-04-11
      • 1970-01-01
      • 2014-12-04
      • 1970-01-01
      • 2022-07-10
      • 1970-01-01
      • 2019-06-21
      • 2019-05-23
      相关资源
      最近更新 更多