Read txt file with no header
8 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Les Beckham
2022 年 4 月 22 日
編集済み: Les Beckham
2022 年 4 月 22 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!