num2mass.m
来自「航天工程工具箱」· M 代码 · 共 43 行
M
43 行
function str=num2mass(m,tab)
%NUM2MASS Displays mass in SI-units.
% STR = NUM2MASS(M,TAB) returns a string containing
% the value of the mass M (in kg) normalized in a proper power
% of grams, kilograms or tons. Argument TAB can be entered
% in order to align the prefix character on a distance of
% at least TAB number of spaces from the last character in
% the normalized value.
% Ex:
%
% num2mass(.21) gives: '210 g'
% num2mass(.21,4) gives: '210 g'
% num2mass(.21,5) gives: '210 g'
% num2mass(12) gives: '12 kg'
% num2mass(.0003) gives: '300 mg'
% num2mass(25054) gives: '25.054 ton'
%
% See also NUM2STR, SEC2HMS.
% Copyright (c) 2002-02-09, B. Rasmus Anthin.
if ~isnan(m) & m e=floor(log10(abs(m*(1+5*3*eps)))); e=e-mod(e,3);else e=0;endif e<3 [s,p]=num2sci(m*1000); if nargin==2 str=[s blanks(tab-length(s)-1) ' ' p 'g']; else str=[s ' ' p 'g']; endelse [s,p]=num2sci(m/1000); if nargin==2 str=[s blanks(tab-length(s)-1) ' ' p 'ton']; else str=[s ' ' p 'ton']; endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?