Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. function y = approx(x, n)
  2. % APPROX Round the number to 1+n significant digits.
  3. % y = APPROX(x) shorthand for round(x, 4, 'significant').
  4. % y = APPROX(x, n) shorthand for round(x, 1 + n, 'significant').
  5.  
  6. % Copyright 2016 Pyry Jahkola
  7.  
  8. if nargin < 2
  9. n = 3;
  10. end
  11.  
  12. m = floor(log10(abs(x)));
  13. unit = 10 .^ (max(m) - n);
  14. y = bsxfun(@times, round(bsxfun(@rdivide, x, unit)), unit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement