0
diary_file = tempname();
diary(diary_file);
myFun();
diary('off');
output = fileread(diary_file);
strToSearch = 'variable failed'
是否有一個已知函數來計算輸出文件中字符串的出現?計數輸出字符串的次數MATLAB
diary_file = tempname();
diary(diary_file);
myFun();
diary('off');
output = fileread(diary_file);
strToSearch = 'variable failed'
是否有一個已知函數來計算輸出文件中字符串的出現?計數輸出字符串的次數MATLAB
只需使用strfind
:
>>output = 'this sentence is a test sentence';
>>strToSearch = 'sentence';
>>numel(strfind(output,strToSearch))
ans =
2
strfind
告訴你的起始指數在尋求字符串(strToSearch
)位於文本(output
)內;和numel
告訴你有多少這樣的指數。