How can we skip specific string with textscan or textread?
이전 댓글 표시
Hello,
I have a file .txt which contains the following text:
VT970103 KOR T. 5 P P2 P2
JAS
CTC N VT980023 GRA T. 6
VT943333 MAI A. 7 P1 P2 P2
JC1 VT910209 MER T. 8 P U2 P
JAS
CTC VT965366 KIR M. 9 P2
RH856957 DIOP C. 10 P2 P2 P P
VT860609 KOR M. (CAP) 11 P P P P1
JC1 VT940239 BER R. 12 P2
JC1 OH883091 FAL M. 14 P2 P2 T1
VT900521 JEN T. 15 P P P2 T1
VT740910 JAC J.TC
I would like to extract three datas of each line. For example for the first line: 'VT970103' , 'KOR T' and '5'.
I use the following function textscan:
fid = fopen( 'text.txt', 'r' );
lic = textscan(fid, '%s %[ABCDEFGHIJKLMNOPQRSTUVWXYZ ] %[^1234567890] %d %*[^\n]')
fclose(fid);
It works when the line has the same format as the first line. But I would like to skip the second line for example because there is not any interesting information. For the third line I would like to skip 'CTC N', and begin to read at VT, and so on.
The common feature to begin to read a line would be when you have a string which contains 2 letters and 6 figures one after the other without any whitespace.
I hope my description is enough clear.
Thank you for your help.
채택된 답변
추가 답변 (1개)
Jan
2016년 11월 11일
0 개 추천
Read the file line by line using fgetl. Then split the first word by strtok and check, if it matchs the pattern. If so, you can parse it by your textscan command.
댓글 수: 1
Sagar Talaviya
2018년 1월 23일
편집: Walter Roberson
2018년 1월 23일
I do have doubts with textscan and regexp. will you help? link to my question: https://de.mathworks.com/matlabcentral/answers/378134-problem-regular-expression-to-analyse-text-file
카테고리
도움말 센터 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!