Finding the first occurance of a given string

20 次查看(过去 30 天)
I have a large text file in which I need to find the first occurance of a given string, e.g. 'STAX'. How can I do this?

采纳的回答

KSSV
KSSV 2016-11-11
编辑:KSSV 2016-11-11
fid = fopen('filename','r') ;
S = textscan(fid,'%s','Delimiter','\n');
S = S{1} ;
%%Get the line number of your string 'STAX'
idxS = strfind(S,'STAX'); % find the index of your string
idx = find(not(cellfun('isempty',idxS))); % your required indices
S(idx)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by