How to scan text file?

12 views (last 30 days)
Mira le
Mira le on 8 Jan 2020
Answered: Bhaskar R on 8 Jan 2020
Hello every one
I have a text file contains:
I want to scan it
How can I do that , please help me!

Accepted Answer

Walter Roberson
Walter Roberson on 8 Jan 2020
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.

More Answers (1)

Bhaskar R
Bhaskar R on 8 Jan 2020
data = readtable('yourfile.txt', 'Delimiter', ',',...
'HeaderLines', 0, 'ReadVariableNames',false, 'Format', '%d');


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by