Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Reading in the leading zeros in a .dat file

Status
Not open for further replies.

jpr105

Computer
Feb 7, 2007
12
0
0
GB
Hi everyone,

I am trying to read a parsed xml file in the form of a .dat file into matlab. I have been using load filename.dat to obtain my matrix in the variable filename, but whenever I go to use the matrix, the leading zeros are missing from the first column.

The dat file has the following (shortened) contents:

0110 8 267 1 287
0111 10 266 3 286

Is there anyway that it can read it exactly how it is in the .dat file including these leading 0's?

Any help would be much appreciated.

Many thanks,

J
 
Replies continue below

Recommended for you

Thanks for the speedy response.

How exactly do I read them in as strings? what is the format command?

I have:
fid = fread(filename);
A = fscanf(fid, format);

where I can't seem to find the correct format...

Thanks,

J
 
Have a look in the Matlab help browser for more information on the format string. the Matlab fscanf function is very similar to the C function of the same name. Have a look in a C manual for more info.

M

--
Dr Michael F Platten
 
Hi,

AFAIK, you can't store integers with leading zeros in a matrix.

You can try something like this :

M=dlmread('sample.dat');
sprintf('%04d\n',M:),1))

Jérôme
 
Many thanks for the help guys,

M=dlmread('sample.dat');
sprintf('%04d\n',M:),1))

allowed me to get my data in the form i needed, but I have found another way around it so it's formatted when I am checking the values.

J

 
Status
Not open for further replies.
Back
Top