Read txt file with no header
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Les Beckham
on 22 Apr 2022
Edited: Les Beckham
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!