Reading header section only from file

11 Ansichten (letzte 30 Tage)
Dhani Dharmaprani
Dhani Dharmaprani am 17 Jan. 2017
Kommentiert: Walter Roberson am 6 Feb. 2020
Hi,
I have a .txt file consisting of a header section and data section (attached). I am interested in only reading the header portion of the file, but what is the best way to do this? I would like the final output to be stored as a char as shown in the picture below, and have tried fscanf to do so but can't quite figure it out.
I am quite a novice with Matlab so any help is greatly appreciated!

Akzeptierte Antwort

Image Analyst
Image Analyst am 17 Jan. 2017
Try this:
str = fileread('test.txt')
index = strfind(str, '[Data]');
header = str(1:(index-1));
  5 Kommentare
leydy Garcia
leydy Garcia am 6 Feb. 2020
what is [Data] in this example?
Walter Roberson
Walter Roberson am 6 Feb. 2020
[Data] is line 295 of the user's file test.txt . It is the header that marks the end of the section the user wants to extract; the user wants the header section of the data rather than the numeric data.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by