4.0

4.0 | 1 rating Rate this file 32 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

Code covered by the BSD License  

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

Download Now | 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.)
Zip File Content  
Other Files license.txt,
spa_sf.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
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 ?

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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com