MATLAB 判斷字符串中是否含有特定的字符


這個程序的目的是,逐行讀取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
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM