I have a file(res.txt) that looks like this:
a
na
na
a
a
a
na
I need to read this into a matrix and import into workspace. using textscan makes it a cell array. hence, a(2)=n not na . How do I import this file into a 1D matrix?
Try:
fid = fopen('file.txt','rt')
C = textscan(fid, '%s', 'Delimiter',''); C = C{1};
fclose(fid);
Now each element of the cell array C{i} contains one line.
If you want an actual character matrix (padded with spaces of course), convert the cell array using:
arr = char(C);
Now each line is: arr(i,:) (might want to use deblank on that)