Strange dlmread tab-delimited import results

9 次查看(过去 30 天)
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 个评论
Jan
Jan 2012-10-21
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 2012-10-21
Thanks for the feedback. I have updated my post accordingly.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2012-10-21
dlmread() is for numeric values only, and is not suitable for reading files that contain ':'. Use textscan() instead.
  1 个评论
Walter Roberson
Walter Roberson 2012-10-21
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by