Finding the first occurance of a given string
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Akzeptierte Antwort
KSSV
am 11 Nov. 2016
Bearbeitet: KSSV
am 11 Nov. 2016
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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!