image thumbnail

Round with significant digits

version 1.6.0.0 (3.05 KB) by François Beauducel
Rounds towards the nearest number with N significant digits.

6.6K Downloads

Updated 03 Apr 2015

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This little function rounds a number (or the elements of a vector ot matrix) towards the nearest number with N significant digits.
Examples:
roundsd(0.012345,3) returns 0.0123
roundsd(12345,2) returns 12000
roundsd(12.345,4,'ceil') returns 12.35
This is a useful complement to Matlab's ROUND, ROUND10 and ROUNDN (Mapping toolbox), especially when dealing with data with a large variety of order of magnitudes.

I was about to upload this file when I found "sd_round.m" by Edward Zechmann (see aknowledgment), which has similar feature (and more). But, because my script is very different in coding (much much shorter), I decided to share it anyway.

Cite As

François Beauducel (2021). Round with significant digits (https://www.mathworks.com/matlabcentral/fileexchange/26212-round-with-significant-digits), MATLAB Central File Exchange. Retrieved .

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

Inspired by: Round to a Specified Number of Significant Digits

Inspired: RADIOMICS

Community Treasure Hunt

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

Start Hunting!