File Exchange

image thumbnail


version (2.08 KB) by Tom R
Round a vector of values towards a given vector of choices.


Updated 14 Dec 2018

View License

This function will round an inputed matrix, of any size, and round each value towards the vector of choices given. It can also be given a type of round ('floor','fix','ceil','round','away'), and will round toward -inf,0,inf,closest value, or away from 0 respectively.

Cite As

Tom R (2020). roundtowardvec (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)


needed to tweak, doesn't ignore nans


Chris H

Worked great!

Qinmiao Li

Easy to use. Great thanks!


super grateful for this easy solution!

Josh Philipson


This is excellent


Made code more memory efficient by not storing new version of vector

Tweaked NaN ignoring.

Added capability of ignoring NaN when a round vector is given.

Description Change, and required version update.

Vectorized rounding operations for speed.

Little tweaks for speed

The function can now round away from 0 (the opposite of floor).

Fixed problem with round when the number is in between two integers.

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Round to X