I am reading a text file in matlab
. Here is the code
allData = textread(file\', \'%s\', \'delimiter\', \'\\n\');
numericalArray = cellfun(@(s) ss
There are various ways to read this sort of data (space-delimited). In all methods precision is preserved.
Assuming you have the input in demo.txt
:
textscan
fid = fopen('demo.txt','r'); % open for reading
txt = textscan(fid,'%s','delimiter', '\n'); txt = txt{1}; % read lines and unbox
fclose(fid);
H = strsplit(txt{1},' '); % split the headers line
V = str2double(strsplit(txt{2},' '));
R = dlmread('demo.txt',' ',1,0); % this is an example in the documentation of dlmread
T = readtable('demo.txt');