How to read numbers from a txt file with numbers and text
3 次查看(过去 30 天)
显示 更早的评论
Hi there,
I have a txt file as the attached one.
I want to read only the numbers, in order to elaborate after the data into a matrix.
I'm trying with this code, but it does not work, cause it does not read the last columns.
path1='.../path1'
fid = fopen(path1);
data = textscan(fid,'%s%f%f%f%f%s%s%f%f','HeaderLines',1,'CollectOutput',1);
data = data{1,1};
fid = fclose(fid);
Can anyone help me? Thanks in advance
0 个评论
采纳的回答
Image Analyst
2020-5-16
Try readtable():
t = readtable('example.txt')
data = t(:, [1:4,11,12])
2 个评论
Image Analyst
2020-5-17
There is a table2array() function if you want to convert the table to a matrix.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!