Why does the behavior of conversion character specifiers for FPRINTF differ from what is observed in C?
1 view (last 30 days)
Show older comments
When I use the FPRINTF function with the conversion character specifiers %x, %c, %u, %d, %i or %o for an invalid input argument, MATLAB returns the same input argument expressed in exponential form.
For example, when I execute the following code:
fprintf('%x\n',-1.5)
fprintf('%c\n',-1234.5)
fprintf('%u\n',-1234.5)
fprintf('%d\n',-1.5)
fprintf('%i\n',-21.5)
fprintf('%o\n',21.5)
MATLAB returns:
-1.500000e+000
-1.234500e+003
-1.234500e+003
-1.500000e+000
-2.150000e+001
2.150000e+001
Rather than returning my input in exponential form, I would expect MATLAB to return warnings or errors to reflect the presence of invalid input arguments.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
Note that although MATLAB's low-level file I/O routines are similar to those in C, they do not behave exactly the same way. This is expected behavior for MATLAB.
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!