how can dertermination which line of string on text file

3 vues (au cours des 30 derniers jours)
Long Hà Vinh
Long Hà Vinh le 5 Mai 2017
Commenté : Long Hà Vinh le 5 Mai 2017
Hi I have some text file like that (named data.txt)
2006 1 6 1150 4.6 L
2006-01-06-1149-59
2006 1 6 1149
....
STAT SP IPHASW D HRMM SECON
2006 1 6 1149 *bold*
with line "STAT SP IPHASW D HRMM SECON" will appear on other line on other file (for eg: this file on line 20, other file on line 25). Q: how can i catch what number of line have "string" STAT SP IPHASW D HRMM SECON Thanks in advance and sorry for my bad english

Réponse acceptée

KSSV
KSSV le 5 Mai 2017
fid = fopen('txt file') ;
S = textscan(fid,'%s','delimiter','\n') ;
fclose(fid) ;
S = S{1} ;
idx = strfind(S, 'STAT SP IPHASW D HRMM SECON');
idx = find(not(cellfun('isempty', idx)))
  3 commentaires
KSSV
KSSV le 5 Mai 2017
idx is the line number where your string STAT SP IPHASW D HRMM SECON is present.
Long Hà Vinh
Long Hà Vinh le 5 Mai 2017
Ya. it work. My bad. Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by