How to extract every repeated sequence line from text file using MATLAB

Time(sec) 20.30
Type 1
Svid slew power used
12. 0.33 -36dbm y
10 .38. -40dbm N
08. 0.40 -30dbm Y
Time(sec) 20.40
Type 2
Svid slew power used
12. 0.46. -38dbm Y
06. 0.50. -32dbm Y
02. 0.42. -30dbm N
sequence repeats....
How to pull out all Type-1 SVID 12 row which is repeating (say after 10 line). How can I save it to new file so that I can manipulate for further processing. Any help is highly appreciated! POKA

5 Kommentare

per isakson
per isakson am 3 Aug. 2017
Bearbeitet: per isakson am 3 Aug. 2017
I didn't understand your last question, which was very similar to this one. And I don't understand this question.
What exactly do you want to write to the new file?
My last question which I posted yesterday night was not clear because of my editing issue. So today same question I have repeated again
Hi , As you can see there are two type of data under two heading Type 1 and Type 2 having different time instance . These are satellite data .At one time I want to extract all data row of psricular sv id corresponding to time . this sv is repeated after particular sequence. So my intention is to pull out say all Sv id 12 of type 1 data .
I got the solution using
KSSV initial reading
file technique
and then pulling data
using indexwise

Melden Sie sich an, um zu kommentieren.

Antworten (1)

You can get the indices of your string Type 1 and Svid1 using the below code:
fid = fopen('data.txt') ;
S = textscan(fid,'%s','delimiter','\n') ;
S = S{1} ;
fclose(fid) ;
%%gEt string Type 1
idx1 = find(not(cellfun('isempty', strfind(S, 'Type 1')))); % lower then 2016b
% idx1 = contains(S,'Type 1') ;
% idx1 = find(idx==1) ;
% GEt string Svid
idx2 = find(not(cellfun('isempty', strfind(S, 'Svid'))));
Once you have indices you can extract what you want..

9 Kommentare

Okay thanks for response . I will check it . what is idx==1 doing here . did not get this part
Hello,
I m getting undefined function cell.
Check is S is your complete text data or not......which line number error comes? What version you are using?
I got it ! S=S{1}; X=S(2:4:end,:); Where x is my sv id staring location and will search after every 4th interval till end.thanks it worked.I did not know textscan is so powerful !
Thanks is accepting the answer :)
textscan is as powerful as the cheap:
S = strsplit(fileread(FileName), '\n');
@Jan Simon, with strings that has CRLF as newline character, strsplit and textscan use the delimiter \n differently
>> strsplit( sprintf( '%s\r\n%s', 'A','B' ), '\n' )
ans =
'A…' 'B'
>> double(ans{1})
ans =
65 13
>> cac = textscan( sprintf( '%s\r\n%s', 'A','B' ), '%s%s', 'Delimiter','\n' )
cac =
{1x1 cell} {1x1 cell}
>> cac{1}
ans =
'A'
By default, \r is 'whitespace' for textscan() but strsplit() treats it as just another character.
strsplit() calls regexp(). You can go more directly:
S = sprintf( '%s\r\n%s', 'A','B' );
cac = regexp( S, '\r?\n', 'split');
It's more to it
>> cac = textscan( sprintf( '%s\r\n%s', 'A','B' ), '%s%s', ...
'Delimiter','\n', 'Whitespace','' )
cac =
{1x1 cell} {1x1 cell}
>> double(cac{1}{:})
ans =
65
>>

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Aug. 2017

Kommentiert:

am 4 Aug. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by