x=rounddiv(x,lim)
x : | Number, Vector, Matrix | |
lim : | Limit |
x : | result |
Round to 2 Digits:
rounddiv (rand(10,1),1/3)
This function, rounddiv
, is designed to round a number, vector, or matrix to a specified precision defined by the parameter lim
. The function is part of the SG-Library and was originally named roundn
but was renamed to avoid conflicts with MATLAB's mapping toolbox.
x
will be rounded.x
to the specified precision.x
is a cell array using iscell(x)
.x
is a cell array, the function iterates over each element of the cell array using a for
loop.rounddiv
with the current element and lim
as arguments.x
is not a cell array, the function calculates the quotient as quot = 1/lim
.x
and quot
using MATLAB's round
function.lim
to achieve the desired precision.To round a random vector of 10 elements to 2 digits, you can use:
rounddiv(rand(10,1), 1/3)
Algorithm explaination created using ChatGPT on 2025-08-19 01:14. (Please note: No guarantee for the correctness of this explanation)