NumberFormatter

Flexible number formatting using java.
1,7K download
Aggiornato 25 ago 2005

Visualizza la licenza

Here is a simple example how to use java.text to format numbers using similar syntax to Excel's. # for a number or space, 0 for a number or zero, etc...

I found this useful for plots. I wanted the ability to have tic labels formatted with commas. Rather then writing my own, I use the ability to call java from matlab.

Example:

NumberFormatter(1e4*rand(5,1),'0,000.000')
ans =
'7,452.920'
'6,511.113'
'4,545.918'
'5,231.557'
'5,120.765'

To utilize with plotting:

plot(1:5,2:6);
XTicksVec=str2num(get(gca,'XTickLabel'));
XTicksCell=NumberFormatter(XTicksVec,'0.0');
set(gca,'XTickLabel',XTicksCell);

This works as is for my needs, but I welcome any suggestions for improvement.

Cita come

Stephen Lienhard (2025). NumberFormatter (https://it.mathworks.com/matlabcentral/fileexchange/8361-numberformatter), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R14SP2
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.0.0.0