필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
POKA
POKA 2017년 8월 3일
댓글: per isakson 2017년 8월 4일
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
POKA
POKA 2017년 8월 3일
I got the solution using
KSSV initial reading
file technique
and then pulling data
using indexwise

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

답변 (1개)

KSSV
KSSV 2017년 8월 3일
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
Walter Roberson
Walter Roberson 2017년 8월 4일
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');
per isakson
per isakson 2017년 8월 4일
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
>>

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

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by