iterate through text files and read them as a matrix

2 visualizaciones (últimos 30 días)
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',' []');

Respuesta aceptada

Turlough Hughes
Turlough Hughes el 20 de Oct. de 2019
Editada: Turlough Hughes el 20 de Oct. de 2019
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','[]')
  3 comentarios
Nitish Reddy Kotkur
Nitish Reddy Kotkur el 20 de Oct. de 2019
Editada: Nitish Reddy Kotkur el 20 de Oct. de 2019
yes it did work can you help me with this
im trying to read a text file containing matrix
A = readmatrix('output1.txt','Whitespace',' []'); when i execute it
its displaying
NaN NaN
NaN NaN
NaN NaN
NaN NaN
here output1.txt file contains data in the given manner
[[0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 0 1]
[0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0]]
what else changes can i make .
BTW it worked fine when matrix size is low i.e when every row of matrix is displayed in single line but as size of matrix increases single row is being displayed in multiple lines thats when problem arised.
Turlough Hughes
Turlough Hughes el 20 de Oct. de 2019
Seeing as you've dedicated a question to the above I commented on that thread. Generally speaking I would opt to get the data in a nice format first rather than trying to solve afterwards. How are you generating the data? Or has it just been given to you?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by