Reading a text file without headers

Hi,
I have a text file without headers and starting as shown below with spacing. I have 3652500 rows in the text file. How can I read this text file using MATLAB.
1 1 1 1 0.00 55. 36. 295.
Thanks in advance,

 採用された回答

per isakson
per isakson 2014 年 5 月 22 日
編集済み: per isakson 2014 年 5 月 22 日

0 投票

If all rows have the same number of columns
dlmread, Read ASCII-delimited file of numeric data into matrix
Syntax
M = dlmread(filename)
M = dlmread(filename, delimiter)
M = dlmread(filename, delimiter, R,C)
M = dlmread(filename, delimiter, range)
.
Example in response to comment:
This works fine here (R2013a)
filespec = 'h:\m\cssm\sample\sample.txt';
num = dlmread( filespec );
whos num
returns
Name Size Bytes Class Attributes
num 20x8 1280 double
Doc says
When dlmread infers the delimiter from the formatting of the file, it
treats repeated white spaces as a single delimiter. By contrast, if you
specify a delimiter, dlmread treats any repeated delimiter character as
a separate delimiter.

5 件のコメント

Damith
Damith 2014 年 5 月 22 日
Hi,
Thanks. I got this error.
Error using dlmread (line 141) Mismatch between file and format string. Trouble reading number from file (row 1u, field 1u) ==> @BCDE
I have attached a sample of the file (sample.zip). Can you please have a look at it if possible?
Thanks.
Image Analyst
Image Analyst 2014 年 5 月 22 日
You've marked it as "Accepted" , so is it still not working or did you figure it out?
Damith
Damith 2014 年 5 月 22 日
no it is not working yet. See the error in my above post.
Damith
Damith 2014 年 5 月 22 日
I tried this code
M = dlmread('OUTPUT.txt', '\t');
I am getting this error
Error using dlmread (line 141) Mismatch between file and format string. Trouble reading number from file (row 1u, field 1u) ==> @BCDE
Anybody have an idea.?
per isakson
per isakson 2014 年 5 月 22 日
編集済み: per isakson 2014 年 5 月 22 日
See the example, which I added to the answer.
sample.zip, which you attached, contains a file named sample.txt. This file is not tab delimited, but space delimited.
I failed to reproduce your error.

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2014 年 5 月 21 日

編集済み:

2014 年 5 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by