06-22.txt
来自「MATLABR2006a基础教程」· 文本 代码 · 共 33 行
TXT
33 行
function meters = convert2meters(miles, varargin)
% Converts MILES (plus optional FEET and INCHES input)
% values to METERS.
if nargin < 1 || nargin > 3
error('1 to 3 input arguments are required');
end
function feet = convert2Feet(argsIn)
% Nested function that converts miles to feet and adds in
% optional FEET argument.
feet = miles .* 5280;
if argsIn >= 2
feet = feet + varargin{1};
end
end % End nested function convert2Feet
function inches = convert2Inches(argsIn)
% Nested function that converts feet to inches and adds in
% optional INCHES argument.
inches = feet .* 12;
if argsIn == 3
inches = inches + varargin{2};
end
end % End nested function convert2Inches
feet = convert2Feet(nargin);
inches = convert2Inches(nargin);
meters = inches .* 2.54 ./ 100;
end % End primary function convert2meters
feet = convert2Feet(nargin);
inches = convert2Inches(nargin);
meters = inches .* 2.54 ./ 100;
end % End primary function convert2meters
>> convert2meters(5)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?