Width & Precision Number Formatting in Documentation
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dwight Schrute III
il 4 Mag 2019
Risposto: Star Strider
il 4 Mag 2019
In the Matlab documentation for sprintf (https://www.mathworks.com/help/matlab/ref/sprintf.html), in the Precision section, the second example shown is:
Example: The input arguments ('%6.4f',pi) are equivalent to ('%.*f',6,4,pi)
However, this is not the answer I see when trying it myself. I get 3.1416 for the first set of inputs and 4.000000 for the second set of inputs. I wonder if they meant to use a '*' instead of a '6' in the first set of inputs? If this is indeed an error, it exists in documentation for other functions as well (e.g., fprintf). Would anyone be able to help clarify?
0 Commenti
Risposta accettata
Star Strider
il 4 Mag 2019
Interesting. That seems to be a typographical error in the documentation:
‘Example: The input arguments ('%6.4f',pi) are equivalent to ('%.*f',6,4,pi)’
There is a missing asterisk. It should be:
Out = sprintf('%*.*f', 6,4,pi)
producing:
Out =
'3.1416'
The example just below that has it correct:
‘Example: The input arguments ('%*.*f',6,4,pi,9,6,exp(1)) return '3.1416 2.718282', with 9 and 6 as the field width and precision for the output of exp(1).’
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Discrete Math in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!