2013-12-09 24 views
0
diary_file = tempname(); 
diary(diary_file);   
myFun(); 
diary('off');    
output = fileread(diary_file); 

strToSearch = 'variable failed' 

是否有一個已知函數來計算輸出文件中字符串的出現?計數輸出字符串的次數MATLAB

回答

0

只需使用strfind

>>output = 'this sentence is a test sentence'; 
>>strToSearch = 'sentence'; 
>>numel(strfind(output,strToSearch)) 
ans = 
    2 

strfind告訴你的起始指數在尋求字符串(strToSearch)位於文本(output)內;和numel告訴你有多少這樣的指數。

相關問題