필터 지우기
필터 지우기

how to display data with commas or spaces

조회 수: 14 (최근 30일)
Christopher Ison
Christopher Ison 2016년 12월 5일
댓글: Christopher Ison 2016년 12월 6일
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
David Barry
David Barry 2016년 12월 5일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2016년 12월 6일
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
Christopher Ison
Christopher Ison 2016년 12월 6일
Thank you, that's what I thought. Seems to me that this an output format long overdue. Perhaps someday.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 12월 6일
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
Christopher Ison
Christopher Ison 2016년 12월 6일
Thank you. That's the method I thought I would have to create myself. I will give a try.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by