필터 지우기
필터 지우기

I want to reduce accuracy and precision to 3 digits.

조회 수: 1 (최근 30일)
meh hadi
meh hadi 2018년 4월 25일
댓글: Walter Roberson 2018년 5월 2일
for example I want to a=2.18+0.139; with 3 digits answer must be 2.31. is any way to do this?
  댓글 수: 3
meh hadi
meh hadi 2018년 4월 25일
in further calculatins
Tom Wenk
Tom Wenk 2018년 4월 25일
편집: Tom Wenk 2018년 4월 26일
Then I think you have to use the symbolic toolbox like Walter Robinson stated.
But why do you want to change 2.319 to 2.31 rather than 2.32? If you use this value for further calculations you should round in my opinion..

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

답변 (3개)

Praveen Iyyappan Valsala
Praveen Iyyappan Valsala 2018년 4월 25일
I don't know any inbulit function which can do that. But, you can try something like below
trun=@(num,Ndigits)floor(a*10^Ndigits)/10^Ndigits;
trun_a=trun(a,2);

Walter Roberson
Walter Roberson 2018년 4월 25일
No, there is no built-in way.
You can use the symbolic toolbox with digits set to 3, but that will round rather than truncate.
  댓글 수: 1
Stephen23
Stephen23 2018년 4월 26일
Note that setting the digits does not mean that calculations will be performed with exactly that precision, because calculations may use guard digits.

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


Tom Wenk
Tom Wenk 2018년 4월 25일
Like Walter Roberson stated, I think you have to use the symbolic toolbox for that.
Maybe this function from the toolbox can help you: https://de.mathworks.com/help/symbolic/digits.html
  댓글 수: 3
Tom Wenk
Tom Wenk 2018년 5월 2일
I see, but is there an other way to do it then?
Walter Roberson
Walter Roberson 2018년 5월 2일
For addition: multiply the original values by 100, take floor() or fix(). Do the addition. Divide the result by 100.

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

Community Treasure Hunt

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

Start Hunting!

Translated by