Round to X

버전 1.4.0.0 (3.72 KB) 작성자: W. Owen Brimijoin
Rounds the supplied N-D matrix to the values in a supplied array.
다운로드 수: 418
업데이트 날짜: 2015/3/2

라이선스 보기

Need to round your data to a set of particular values? This function takes as its input the data you want to round, the values you want the data rounded /to/, and a rounding method (currently 'round', 'floor' and 'ceil', that each work the way their .m counterparts do).
The function is vectorized for efficiency.
round2x(data,roundvals,method)
Given an N-dimensional array of numbers, this function will round all the elements of the array to the nearest elements in the supplied vector or ND array.

Example:
data = rand(2,9)*10; %data that you want to round
roundvals = [-1 2 3.14 8]; %numbers you want to round the data to
rounded = ROUND2X(data,roundvals);

If no rounding method is chosen, the function acts like 'round.m' in terms of rounding direction. The following methods can also be called:
'round' (Default: round towards nearest)
'floor' (round towards -infinity)
'ceil' (round towards +infinity)

Example:
rounded = ROUND2X(data,roundvals,'floor');

Happy rounding!

인용 양식

W. Owen Brimijoin (2024). Round to X (https://www.mathworks.com/matlabcentral/fileexchange/47178-round-to-x), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2013b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Arithmetic Operations에 대해 자세히 알아보기
태그 태그 추가
도움

받음: roundtowardvec

Community Treasure Hunt

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

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

Fixed 0.5 error, improved inputs and input checking (including error for complex values), and added a 'See Also' line. Function was also changed in name from round2vec to round2x, to reflect the fact that the round values could ND.

1.3.0.0

In fixing a NaN problem, an Inf problem was introduced. This has been corrected!

1.2.0.0

Changed page name

1.1.0.0

Fixed a ceiling/floor bug that occurred when all values in supplied data were outside the range of the rounding vector. Also added an error check relating to rounding vectors there were either empty or contained NaNs.

1.0.0.0