MATLAB: Iterate through text files and read them as a matrix

formatrixtextfiles

myfolderinfo=dir('dense_gnm_random_graph');%dense_gnm_random_graph is the folder which contains text files
N=length(myfolderinfo);
for i = 3:N
thisfile= myfolderinfo(i).name
A = readmatrix('thisfile','Whitespace',' []');
and these are the errors i got
Error using readmatrix (line 148)
Unable to find or open 'thisfile'. Check the path and filename or file permissions.
Error in final (line 6)
A = readmatrix('thisfile','Whitespace',' []');

Best Answer

You have to make sure your filename and path are correct. Try modifying your input to readmatrix as follows:
A=readmatrix([myfolderinfo(i).folder '\' myfolderinfo(i).name],'Whitespace','[]')