Is it possible for matlab to print output numbers like 0.98765432 merely as .987654 with no fronting zero and only six digits (rounded) ?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Frank Lad
il 15 Mag 2022
Commentato: Walter Roberson
il 18 Mag 2022
Is it possible for matlab to print output numbers like 0.98765432 merely as .987654 with no fronting zero and only six digits (rounded) ?
1 Commento
dpb
il 15 Mag 2022
I don't believe that is within the C Standard i/o specification of a formatting string definition, no...it is helpful in that way of writing prettified fields. Believe you would have to post-process the output to do so to replace the "0." with just "." to get there.
Where do you want/need this to occur?
Risposta accettata
Walter Roberson
il 15 Mag 2022
regexprep(compose("%.6f", YourMatrix), "^0\.", ".")
That would give you a string() array
4 Commenti
Più risposte (1)
the cyclist
il 15 Mag 2022
Modificato: the cyclist
il 15 Mag 2022
x = 0.98765432;
s = eraseBetween(sprintf("%7.6f",x),1,1)
5 Commenti
dpb
il 15 Mag 2022
Modificato: dpb
il 15 Mag 2022
Indeed...although one would presume wouldn't apply it to numbers abs(x(rounded to six places))>=1 since those don't have just a leading 0. that seemed to be the Q?. :)
A one-liner to handle the case doesn't come to me otomh...I'd put this on the caller to not misuse.
Of course, one can also presume the OP would like to have stuff in the command window and elsewhere follow same convention; that, sadly is not possible; the format options are pretty limited. I've often wished could set a format for a table by column -- it's a real pain to have integer variables show up with two decimal points under format bank, but it's even worse for currency values to have varying precision displayed. One way in which spreadsheets have an advantage...
Vedere anche
Categorie
Scopri di più su Graphics Object Programming 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!