필터 지우기
필터 지우기

Help with textscan while reading misc data files

조회 수: 1 (최근 30일)
Sergio
Sergio 2019년 1월 25일
댓글: Sergio 2019년 1월 26일
Hi,
I'm facing a lot of trouble trying to read data from a text file. Basically, the structure is like this:
01B1305.aaa
65536
0.01
8.816667e-05
6.500000e-05
...
5.866667e-05
Timehistories end here
(lots of useless text after the line above)
So, what I want is to read just the block of data between "8.816667e-05" and "5.866667e-05". Could you help me out?
Thanks,
ps: The line "Timehistories end here" actually exists in every file, but I don't need to read it either.

채택된 답변

TADA
TADA 2019년 1월 25일
if you know how many lines you want to skip:
fid = fopen('data.txt'); % your own filename comes in here
a = cell2mat(textscan(fid, '%f', 'HeaderLines', 3, 'ReturnOnError', true))
fclose(fid);
  댓글 수: 2
TADA
TADA 2019년 1월 25일
this will work if you Know how many lines to skip and if you want all the numeric data up to the line with 'Timehistories end here'
If there is anything thats not numeric in that range, it will fail. if there's data that you don't want to read before that line, it will read it
Sergio
Sergio 2019년 1월 26일
Awesome! Thanks a lot!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by