Read txt file with no header
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Iacopo
am 22 Apr. 2022
Bearbeitet: Les Beckham
am 22 Apr. 2022
Hi all, I have attached one of the txt I need to extract only the numeric data from, skipping thr headers. it works for that file but I want to extens the code to files with a different (unknown) number of columns. Can anyone help me to modify it?
The piece of code I used is:
fid=fopen('text.txt');
data=textscan(fid,'%f %f %f %f %f %f %f %f %f %f','HeaderLines','4');
data=cell2mat(data);
fclose(fid);
Thanks
0 Kommentare
Akzeptierte Antwort
Les Beckham
am 22 Apr. 2022
Bearbeitet: Les Beckham
am 22 Apr. 2022
This should work for any number of columns and it automatically detects the number of header rows and the variable names.
t = readtable('text.txt')
data = table2array(t); % convert to a plain numeric array
whos data
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps 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!