Borrar filtros
Borrar filtros

dlmread reads rows instead of columns

2 visualizaciones (últimos 30 días)
Alexey Pustovarenko
Alexey Pustovarenko el 11 de Dic. de 2017
Respondida: Yaakov Shaked el 25 de Mzo. de 2019
Hi all,
I have tried to import a column from a .txt file (contains 976 rows and 5 columns of numbers with a tab delimiter) using M = dlmread('filename.txt','\t',[0,0,5,0]), so M should contain first six elements of the first column. It gives 1x6 array instead: the first row of the txt file + 1 element from the second row. So it reads rows instead of columns. Am I missing something? How could I solve this problem? Sorry for my English.

Respuestas (2)

KL
KL el 11 de Dic. de 2017
Editada: KL el 11 de Dic. de 2017
EDITED
something like the following,
dlmread(filename,' ',[0 0 4 0])
or use textscan,
filename = 'dummy.txt';
noRows = 5;
A = cell(noRows,1);
fid = fopen(filename,'r');
fspec = '%f %*f %*f %*f %*f\n'; % use * to ignore reading
for k =1:noRows
A(k,1) = textscan(fid,fspec,1);
end
fclose(fid);
  2 comentarios
Alexey Pustovarenko
Alexey Pustovarenko el 11 de Dic. de 2017
Thanks a lot. It works perfectly. But I'm still wondering why it failed with the dlmread. Is it a bug?
KL
KL el 11 de Dic. de 2017
Not a bug, should be something to do with the file I reckon.
But I'm used to using textscan for custom import as it gives more freedom.

Iniciar sesión para comentar.


Yaakov Shaked
Yaakov Shaked el 25 de Mzo. de 2019
I just ran in to a same problem - the data was being read row by row instead of column by column.
I found out that my delimeter was wrong (a tab insted of a space).
Once I fixed the delimeter, the data was read correctly.

Community Treasure Hunt

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

Start Hunting!

Translated by