Help with textscan while reading misc data files

2 Ansichten (letzte 30 Tage)
Sergio
Sergio am 25 Jan. 2019
Kommentiert: Sergio am 26 Jan. 2019
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.

Akzeptierte Antwort

TADA
TADA am 25 Jan. 2019
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 Kommentare
TADA
TADA am 25 Jan. 2019
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 am 26 Jan. 2019
Awesome! Thanks a lot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by