how to display data with commas or spaces

I am unable to find the syntax to display output data with commas or spaces used to separate groups of three digits in order to improve readability. For example, instead of 3.14159 display 3.141 59 or instead of 200000 display 200,000. Did I miss something?

1 comentario

David Barry
David Barry el 5 de Dic. de 2016
What do you mean by display? Are you referring to the output in the MATLAB command window if you call disp on the variable in question?

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Dic. de 2016

0 votos

There is no "format" option for that, and there is no format specifier for sprintf() or fprintf() for that. You will need to convert your values to string form and process the string.

1 comentario

Christopher Ison
Christopher Ison el 6 de Dic. de 2016
Thank you, that's what I thought. Seems to me that this an output format long overdue. Perhaps someday.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 6 de Dic. de 2016
Use my CommaFormat(), attached. It turns a number into a string with commas inserted:
>> str = CommaFormat(12345678)
str =
12,345,678
>> fprintf('The answer is %s\n', str);
The answer is 12,345,678

1 comentario

Christopher Ison
Christopher Ison el 6 de Dic. de 2016
Thank you. That's the method I thought I would have to create myself. I will give a try.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by