round2

버전 1.2.0.1 (1.39 KB) 작성자: Robert Bemis
Round input to nearest multiple of arbitrary value.
다운로드 수: 14.1K
업데이트 날짜: 2016/9/1

라이선스 보기

Everyone knows about the ROUND function for converting floating point values to their nearest whole number or integer value, but have you ever wanted to round off values to something other than whole numbers? This simple utility function does just that.
Example 1: round PI to 2 decimal places
>> round2(pi,0.01)
ans =
3.14

Example 2: round PI to 4 decimal places
>> round2(pi,1e-4)
ans =
3.1416

Example 3: round PI to 8-bit fraction
>> round2(pi,2^-8)
ans =
3.1406

Examples 4-6: round PI to other multiples
>> round2(pi,0.05)
ans =
3.15
>> round2(pi,2)
ans =
4
>> round2(pi,5)
ans =
5

인용 양식

Robert Bemis (2024). round2 (https://www.mathworks.com/matlabcentral/fileexchange/4261-round2), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R13
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.2.0.1

Updated license

1.2.0.0

Minor bug fix (error message typo)

1.1.0.0

copyright

1.0.0.0

Expanded help text with examples, including binary fraction (analagous to fixed point math).