How to scan text file?
4 次查看(过去 30 天)
显示 更早的评论
Hello every one
I have a text file contains:
1,24,85,90
23,36
34,36,39,56,85,86,90
34,59,67,85,86
39,85,93
I want to scan it
How can I do that , please help me!
0 个评论
采纳的回答
Walter Roberson
2020-1-8
filename = 'AppropriateName.txt';
S = fileread(filename);
L = regexp(S, '\r?\n', 'split');
data = cellfun(@(s) str2double(regexp(s, ',', 'split')), L, 'uniform', 0);
The result will be a cell array with one entry per line, with each entry being the numeric data from the corresponding line.
0 个评论
更多回答(1 个)
Bhaskar R
2020-1-8
data = readtable('yourfile.txt', 'Delimiter', ',',...
'HeaderLines', 0, 'ReadVariableNames',false, 'Format', '%d');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!