rounddiv

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 1.0, Creation date: 2012-07-10, Last change: 2025-09-14

rounds a vector or matrix to a defined number of digits

Description

Renamed in SG-Lib from roundn (conflict with mapping-toolbox into rounddiv)
It is extremely fast procedure!
Unfortunately there existed a MATLAB function with same name already in the mapping toolbox, I was not aware since not using it at this time.
In future, I recommend no to used this function anymore (only in few cases) but to use the concept of round([pi, 6378137], 3, 'significant') with significant numbers instead.


See Also: , rounds

Example Illustration

 missing image of rounddiv(x,lim)

Syntax

x=rounddiv(x,lim)

Input Parameter

x: Number, Vector, Matrix
lim: Limit

Output Parameter

x: result

Examples

Round to 2 Digits:
rounddiv (rand(10,1),1/3)




Copyright 2012-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

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.

Input Parameters

Output

Algorithm Steps

  1. The function first checks if x is a cell array using iscell(x).
  2. If x is a cell array, the function iterates over each element of the cell array using a for loop.
  3. For each element in the cell array, the function recursively calls rounddiv with the current element and lim as arguments.
  4. If x is not a cell array, the function calculates the quotient as quot = 1/lim.
  5. The function then rounds the product of x and quot using MATLAB's round function.
  6. The result is multiplied by lim to achieve the desired precision.

Example

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)

Last html export of this page out of FM database by TL: 2025-09-21