這個程序的目的是,逐行讀取file.txt文件中的字符串,並判斷字符串中是否含有特定的字符,如果含有,再對字符串進行處理,然后寫入到新的TXT文檔中new_file.txt
fid=fopen('D:\new_file.txt','wt'); phns = 'D:\file.txt'; fpn = fopen (phns(1,:), 'rt'); % while feof(fpn) ~= 1% file = fgetl(fpn); if ~isempty(strfind(file,'m')) %如果字符串中含有“m”則執行if內的程序 end fprintf(fid,'%s',file); end fclose(fid); fclose(fpn);
或者使用contains()函數:
filename='/media/dell/D/qcc/code/pointnet/pointnet2-master/data/dianyun_biaoxian_yifenlei/5-10_dashline_seg_python_dealwith.xyz';
>> contains(filename,'dashline')
ans =
logical
1
