Azzera filtri
Azzera filtri

Strange dlmread tab-delimited import results

10 visualizzazioni (ultimi 30 giorni)
Link
Link il 21 Ott 2012
Hi!
I am using dlmread to import tab delimited data from a text file with headers. I use something like what was discussed here to read the number of rows of my dataset prior to importing it.
So I use the command:
x = dlmread('data.txt', '\t', [22 1 1117 6]);
where 22 is a constant number of header rows, 6 is the number of columns I want to import, and in this case 1117 is the total number of rows in the file. (note, I am ignoring the last column of my dataset - a time signature - for the moment).
My data looks something like:
0.002500 \t 1379.728905 \t 26.014343 \t -0.001847 \t 0.022119 \t -0.006115 \t 13:53:01:.269 \n 0.002500 \t 1379.725659 \t 26.009462 \t -0.003488 \t -0.017605 \t -0.007100 \t 13:53:02:.582 \n
Just focusing on the first column, after the import I would expect >> x(1:2,1)
ans =
0.0025
0.0025
but instead I am getting:
ans =
0.0025
0
and between every good data row, I am getting a zero. Even if I just try to import the first column instead of all six, I am still getting the same strange results.
Any help or suggestions would be appreciated!
  2 Commenti
Jan
Jan il 21 Ott 2012
What does "my data looks like" exactly mean? Does the file contain the square brackets? Perhaps the format of the file gets clear, when you use the standard formatting features of this forum. But it might be important to mark, where the Tabs are in this file.
Link
Link il 21 Ott 2012
Thanks for the feedback. I have updated my post accordingly.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 21 Ott 2012
dlmread() is for numeric values only, and is not suitable for reading files that contain ':'. Use textscan() instead.
  1 Commento
Walter Roberson
Walter Roberson il 21 Ott 2012
This applies even if you are restricting the output to columns that contain only numeric values. dlmread() uses an undocumented behavior of textscan() that functions only on pure numeric input, and then dlmread() throws away the columns that are not wanted.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by