要在MATLAB中读取PLY格式文件,你可以使用以下代码: ```matlab % 读取PLY文件 function [vertices, faces] = read_ply(filename) fid = fopen(filename, 'r'); if fid == -1 error('无法打开文件'); end % 跳过文件头 while true line = fgetl(fid); if strcmp(line, 'end_header') break; end end % 读取顶点和面数据 vertices = []; faces = []; while true line = fgetl(fid); if feof(fid) break; end % 解析顶点数据 if startsWith(line, 'v ') vertex = str2num(strsplit(line, ' ')); vertices = [vertices; vertex]; end % 解析面数据 if startsWith(line, 'f ') face = str2num(strsplit(line, ' ')) - 1; % 减1是因为MATLAB索引从1开始 faces = [faces; face]; end end fclose(fid); end ``` 使用这个函数,你可以像这样读取一个PLY文件: ```matlab [vertices, faces] = read_ply('example.ply'); ``` [2024-05-14 14:55:52 | AI写代码神器 | 341点数解答]