Dear all, I have vector with numbers and fraction. How can I reduce fraction number.?for example a=[1.23456789 6.14521456 7.906342678 10.47609352]
expect results should be: re=[ 1.2 6.1 7.9 10.4] Thanks...

 채택된 답변

the cyclist
the cyclist 2017년 1월 30일
편집: the cyclist 2017년 1월 30일

1 개 추천

One way to display a decimal number to one decimal place:
sprintf('%5.1f',a)
Note that this will not change the value stored in a; it will only display it differently.

댓글 수: 3

skysky2000
skysky2000 2017년 1월 30일
Thanks the cyclist,,,, when I make it as below, showed me as 1 cell not vector: re=sprintf('%5.1f',a);
the cyclist
the cyclist 2017년 1월 30일
편집: the cyclist 2017년 1월 30일
If you want to store a value that is changed, use the round function:
re = round(a,1)
Or you might want fix instead.
skysky2000
skysky2000 2017년 1월 30일
That amazing 100% work..... thanks alots

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

추가 답변 (1개)

Steven Lord
Steven Lord 2017년 1월 30일

0 개 추천

See the second input of the round function.

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2017년 1월 30일

댓글:

2017년 1월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by