Code covered by the BSD License  

Highlights from
Rounding Off Number(s) to Specified Significant Figures

3.75

3.8 | 4 ratings Rate this file 42 Downloads (last 30 days) File Size: 1.3 KB File ID: #23949

Rounding Off Number(s) to Specified Significant Figures

by Yuzo Toya

 

28 Apr 2009

Round off number(s) to specified significant figures, using two simple/powerful MATLAB functions.

| Watch this File

File Information
Description

spa_sf Rounding Off Number(s) to Certain Significant Figures

N = spa_sf(X,SF) is the rounded off number(s) of X with the specified significant figures SF. X could be a scalar or a vector; however, SF must be a scalar.
 
   Example 1)
       X = 3.14159265359;
       SF = 3;
       N = spa_sf(X,SF)

     > N = 3.1400

   Example 2)
       X = 3.14159265359; X=[X,X*2;X*3,X*4];
       SF = 3;
       N = spa_sf(X,SF)

     > N =
           3.1400 6.2800
           9.4200 12.6000

 See also: num2str, str2num
   

* I hope it would be of any help.

MATLAB release MATLAB 7.8 (R2009a)
Other requirements N/A (I've used this function since MATLAB 6.X.)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
29 Apr 2009 Jos (10584)

Yes, too simple and its functionality is already abundantly available here of the FEX. However, I should compliment you for the nice help section!

29 Apr 2009 Yuzo Toya

The beauty rests in the simplicity of it all, but I am not claiming for its originality -- it's all there in the MATLAB tool package. I decided to share "this code" mainly because of its simplicity, and hope that you will find it useful in any way.

22 Jun 2009 Yuzo Toya

Note: This function provides expected results when handing numerical values in double or less precision.

25 Nov 2009 Robert Orzechowski

it is nice, but how to round-off complexed values ?

28 Jul 2010 Geoffrey Lewen  
22 Apr 2011 Neha

It is not working. I am trying to round off a matrix which contains double values, it shows the error:
Undefined function or method 'spa_sf' for input arguments of type 'double'.

30 Apr 2011 Yuzo Toya

Neha, You probably did not place the program / code (spa_sf.m) in the MATLAB's search path. Try running the program after moving the file "spa_sf.m" to the MATLAB's search path or to the current directory. Alternatively, you can set the path to the directory where the file "spa_sf.m" is stored on your computer. (From the Menubar, File >> Set Path...)

22 Jan 2012 SK  
28 Jan 2012 Yonghao

How to ceil/floor round to the significant number?

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
significant figures Yuzo Toya 29 Apr 2009 09:54:42
significant digits Yuzo Toya 29 Apr 2009 09:54:42
rounding Yuzo Toya 29 Apr 2009 09:54:42
precision Yuzo Toya 09 May 2009 12:09:08
round Yuzo Toya 09 May 2009 12:48:08
decimal Yuzo Toya 09 May 2009 22:16:33
sigfig Yuzo Toya 09 May 2009 22:16:40
sig fig Yuzo Toya 09 May 2009 22:16:46
decimal places Yuzo Toya 07 Aug 2009 12:09:38

Contact us at files@mathworks.com