Reputation: 10946
What are the valid formats are for numbers in MATLAB? The following seem to be valid:
x=0;
x=0.;
x=0.0;
x=0e0;
x=0E0;
x=0000.00; % Trailing and leading zeros seem to be irrelevant
Are there other valid general number specifications? I can't find this in the documentation.
Upvotes: 3
Views: 75
Reputation: 38032
I believe this is the regex of floating-point number formats, valid in MATLAB:
^[-+]*([0-9]+|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)([eEdD][+-]?[0-9]+)?$
Compiled from here, and slightly modified for MATLAB:
'd'
exponent character (as is common in FORTRAN, MATLAB's ancestor)I'm pretty sure the locale can mess this up, e.g., the decimal separator .
might be set to ,
as is common here in Europe. Oh well.
The regex in words:
e
, E
, d
or D
. Note that this is for non-complex floating point values. For complex values, you'd have to
[ij]{1}
to the imaginary part (only lower case) \s*
) and a [+-]{1}
in between the two parts[+-]{1}
, but no imaginary part.Upvotes: 4