how to search for a string inside a file in matlab
8 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Jan
2016-10-22
编辑:Jan
2016-10-26
Guessed, tha the .dat file is a text file and you want to search fpr the occurence of a string anywhere in a line:
fid = fopen(FileName, 'r');
if fid == -1
error('Cannot open file: %s', FileName);
end
key = 'YourStr';
data = 'not found';
ready = false;
lineNo = 0; % [EDITED]
while ~eof(fid) && ~ready
S = fgetl(fid);
lineNo = lineNo + 1; % [EDITED]
if any(strfind(S, key))
data = YourReadMethod;
ready = true;
end
end
fclose(fid);
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!