Trouble parsing string, possible bug in strread or dataread?

Dear MATLAB community,
I'm currently debugging a a piece of code where I have to convert a string to a meaningful representation. Of course, I know of the function str2num which behaves correctly:
str2num('20130419145047566000')
ans =
2.0130e+19
If I use the strread function on the string '20130419145047566000' I get following result
strread('20130419145047566000', '%d', 'delimiter', ',')
ans =
-1.8743e+09
The documentation states that it behaves much like the fscanf function found in the standard C++ library. It states 'd = Decimal integer: Number optionally preceeded with a + or - sign' The above data type is a double.
Is this a bug in the dataread function or am I using it wrong?

Answers (1)

%d in C++ is for data type int, not for datatype long int. %ld would need to be used in C++ for a 64 bit number.
However, the number exceeds 64 bits, and needs 65 bits to represent as an integer. There is no integral data type longer than 64 bits in MATLAB.
You should be using %f for the format, not %d

Products

Asked:

on 1 Oct 2013

Answered:

on 1 Oct 2013

Community Treasure Hunt

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

Start Hunting!