发布网友
共4个回答
热心网友
matlab 中的函数参数个数,是你自己在函数中定义的啊,跟你函数里要调用的外部变量的个数相同。
例如:
主函数:
clc;clear;
sex = 0;
% a表示性别,1 表示男,0表示女
age = 11;
% b表示岁数
kid(sex,age);
函数kid:
function high = kid(a,b)
%计算10到15岁小孩身高
if(b>=10 && b<=15)
if (a == 1)
high = b*0.1;
fprintf('the height of the boy is %1.3f m\n',high);
elseif (a == 0);
high = b*0.105;
fprintf('the height of the girl is %1.3f m\n',high);
else
fprintf('out of sex range\n');
end
else
fprintf('out of age range\n');
end
热心网友
查看m文件的用法
1 建立一个m文件
2 function kid(a,b)
kid=a+b
(注: 文件名为 kid.mat)
3 回演算页, 输入kid(2,3)
会出现 5
热心网友
你分开编吧
一个kid1,一个kid2
不太可能按你的要求定义函数
计算机看不懂的
热心网友
matlab
中的
函数
参数
个数,是你自己在函数中定义的啊,跟你函数里要调用的
外部变量
的个数相同。
例如:
主函数:
clc;clear;
sex
=
0;
%
a表示性别,1
表示男,0表示女
age
=
11;
%
b表示岁数
kid(sex,age);
函数kid:
function
high
=
kid(a,b)
%计算10到15岁小孩身高
if(b>=10
&&
b<=15)
if
(a
==
1)
high
=
b*0.1;
fprintf('the
height
of
the
boy
is
%1.3f
m\n',high);
elseif
(a
==
0);
high
=
b*0.105;
fprintf('the
height
of
the
girl
is
%1.3f
m\n',high);
else
fprintf('out
of
sex
range\n');
end
else
fprintf('out
of
age
range\n');
end