필터 지우기
필터 지우기

How do I get MatLab to format to three (3) deceimal places?

조회 수: 12 (최근 30일)
Eric Metzger
Eric Metzger 2020년 2월 6일
댓글: Star Strider 2020년 2월 6일
This may sound like a silly question but I need to get MatLab to format real number output to three (3) decimal places. I know format bank will do two (2) decimal places and the format short G or format shortg will do decimal places to five (5) deceimal places but I only need three (3). Is there a way to get MatLab to do that?

채택된 답변

Star Strider
Star Strider 2020년 2월 6일
The round function has several options, however using it will change how the numbers are represented internally, not only how they are displayed.
It might be most appropriate to usse sprintf with the '%.3f' format descriptor to do what you want.
  댓글 수: 2
Eric Metzger
Eric Metzger 2020년 2월 6일
Been using the round option but sometimes it woudl force a whole number as round deals primarily with integers. However, noticed where that was happeneing, I was missing a ")" or a "," in the line.
I also force alot of my output into a .txt files using the fprintf function, then reload as needed later. This forces MatLab to use the numbers in the format it is given. I also do this to create a record of what was produced (helps a lot with debugging). Just wish it didn't slow down the script the way it does.
Thanks for your input, will use it in the areas where the information generated is not output first. Looks like this came down to syntax again.
Star Strider
Star Strider 2020년 2월 6일
My pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by