I want to find a specific text line in my text file, how do i code this? In this code I want to fill in time and then get the number of colum two, is there anybody who can help?
09:48:40 0 1
09:48:42 0 1
09:48:44 0 1
09:48:46 0 1
09:48:48 0 1
09:48:50 0 1
09:48:52 0 1
09:48:54 0 1
09:48:56 1788 1
09:48:58 0 1
09:49:00 0 1
09:49:02 0 1

댓글 수: 4

Walter Roberson
Walter Roberson 2020년 10월 25일
If you use a timetable object then you can index directly by the time.
sander de lange
sander de lange 2020년 10월 25일
Hi guys Thanks for the quick reaction. However I think wasn't that clear. But what I want is a code/function that gives me the linenumber of for example 9:48:56. Can you guys help me with that?
Peter Perkins
Peter Perkins 2020년 11월 19일
+1 to Walter's suggestion. Make a timetable with duration row times, then just use 9:48:56 as a row subscript, perhaps as tt('9:48:56',:) or perhaps as tt.Var1('9:48:56').

댓글을 달려면 로그인하십시오.

답변 (2개)

Stephen23
Stephen23 2020년 10월 25일

0 개 추천

>> T = readtable('temp0.txt','Delimiter','\t','ReadVariableNames',false)
T =
Var1 Var2 Var3
__________ ____ ____
'09:48:40' 0 1
'09:48:42' 0 1
'09:48:44' 0 1
'09:48:46' 0 1
'09:48:48' 0 1
'09:48:50' 0 1
'09:48:52' 0 1
'09:48:54' 0 1
'09:48:56' 1788 1
'09:48:58' 0 1
'09:49:00' 0 1
'09:49:02' 0 1
>> X = strcmp(T.Var1,'09:48:56');
>> Y = T.Var2(X)
Y =
1788
Walter Roberson
Walter Roberson 2020년 10월 25일

0 개 추천

fileread and regexp() 'split' using pattern '\r?\n' on that to get lines. Now regexp() that cell array of character vectors giving the target time as the pattern and 'once' option. cellfun @isempty and ~ the resulting vector and find() to get the line number.
This for the new requirement that the desired output is the line number. The code for the original task of extracting the second column would have been notably simpler.

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

질문:

2020년 10월 25일

댓글:

2020년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by