how to display data with commas or spaces
Show older comments
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 Comment
David Barry
on 5 Dec 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?
Accepted Answer
More Answers (1)
Image Analyst
on 6 Dec 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 Comment
Christopher Ison
on 6 Dec 2016
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!