function rounded_val=rnd_orderofmag(val) Rounds val to lowest non-zero digit
0001 function rounded_val=rnd_orderofmag(val) 0002 %function rounded_val=rnd_orderofmag(val) 0003 % 0004 % Rounds val to lowest non-zero digit 0005 0006 orig_val=val; 0007 val=abs(val); 0008 if val>=1 0009 ord=1; 0010 val=floor(val/10); 0011 while val>=1, 0012 ord=ord*10; 0013 val=floor(val/10); 0014 end 0015 else 0016 ord=1/10; 0017 val=val*10; 0018 while val<1, 0019 ord=ord/10; 0020 val=val*10; 0021 end 0022 end 0023 0024 rounded_val=round(orig_val/ord)*ord;