I have to read a lot of text files in a folder which only have one matrix in them. So I found and tested that dlmread
is good when I write a file's name. But I couldn't have MATLAB read them all.
How can I correct this small code and If there is better way, please write.
files = dir('C:\Users\ABC\Desktop\a\*.txt')
for k = 1:length(files)
fname= files(k).name
M = dlmread('fname') % This part is wrong
% REST OF CODE for each Matrix M
end
well fname
really reads the name of file, 1.txt
for example. If I write M = dlmread('1.txt')
myself, it reads matrix to M
, but if I write M = dlmread('fname')
it does not.
How can I do this best?