How to parse (extract) data from a text file?
이전 댓글 표시
Hello! I have the following text file and I want to extract the data marked with red pen. The file has a lot of rows like this, but, the position of the desired data is generally the same. I have tried a few things as in the attached file, but it doesn't seem to work. Any ideas?
Thanks!

댓글 수: 4
Adam
2019년 3월 12일
What does the 'bull at a gate' approach of just calling
doc importdata
give you?
It is surprisingly good at reading data in a variety of formats and managing to put the data into servicable structures within Matlab.
Jan
2019년 3월 12일
"It doesn't seem to work" is a weak description of the occurring problems. You did not define exactly, what you want to extract. Are these specific line numbers or can the lines be identified by the "CANFD" string? In which format do you want to obtain the data? As cell string or by hex2dec?
Razvan Bataiosu
2019년 3월 12일
What exactly is "binary format?" This is not clear for the string
1 0 b 20 61 ...
Please be as sepcific as possible: What is the wanted output for the shown input?
It would be easier to write questions, if you provide the file as text and not as screenshot.
답변 (1개)
Str = fileread(FileName);
CStr = strsplit(Str, char(10));
match = contains(CStr, 'CANFD');
Data = CStr(match);
Data contains the wanted lines now, but it is not clear to me, what you want as output.
카테고리
도움말 센터 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!