Reading in the leading zeros in a .dat file
Reading in the leading zeros in a .dat file
(OP)
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
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





RE: Reading in the leading zeros in a .dat file
M
--
Dr Michael F Platten
RE: Reading in the leading zeros in a .dat file
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
RE: Reading in the leading zeros in a .dat file
M
--
Dr Michael F Platten
RE: Reading in the leading zeros in a .dat file
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
RE: Reading in the leading zeros in a .dat file
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