Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function y = approx(x, n)
- % APPROX Round the number to 1+n significant digits.
- % y = APPROX(x) shorthand for round(x, 4, 'significant').
- % y = APPROX(x, n) shorthand for round(x, 1 + n, 'significant').
- % Copyright 2016 Pyry Jahkola
- if nargin < 2
- n = 3;
- end
- m = floor(log10(abs(x)));
- unit = 10 .^ (max(m) - n);
- y = bsxfun(@times, round(bsxfun(@rdivide, x, unit)), unit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement