1
function experiment4(x)
%UNTITLED 此处显示有关此函数的摘要
% 此处显示详细说明
x=input(‘x=’);
if x<0&&x~=-3
y=x.*x+x-6;
elseif (x>=0)&&(x<5)&&x=2&&x=3
y=x.*x-5.*x+6;
else
y=x.*x-x-1;
end
2
function experiment4(score)
%UNTITLED 此处显示有关此函数的摘要
% 此处显示详细说明
score=input(‘score=’);
if score<=100&&score>=0
switch fix(score/10)
case {9,10}
grade=‘A’;
case {8}
grade=‘B’;
case {7}
grade=‘C’;
case {6}
grade=‘D’;
otherwise
grade=‘E’;
end
grade
else
disp(‘错误!输出成绩无效!’);
end
2 if-else
function experiment4(score)
%UNTITLED 此处显示有关此函数的摘要
% 此处显示详细说明
score=input(‘score=’);
if score<=100&&score>=90
grade=‘A’;
elseif score<90&&score>=80
grade=‘B’;
elseif score<80&&score>=70
grade=‘C’;
elseif score<70&&score>=60
grade=‘D’;
elseif score<60
grade=‘E’;
else
grade=‘N’;
end
if grade==‘N’
disp(‘出错!成绩不合理!’);
else
disp(grade);
end
3
id=input(‘id=’);
time=input(‘time=’);
disp(‘应发工资’)
switch time
case {time>120}
money=(time-120)(1+15/100)84+12084
case {time<60}
money=time84-700
otherwise
money=time*84
end
4
A=floor(rand(1)90+10)
B=floor(rand(1)90+10)
x=input(‘输入一个运算符:’,‘s’);
switch x
case {‘+’}
c=A+B;
case {‘-’}
c=A-B;
case {''}
c=AB;
case {‘/’}
c=A/B;
otherwise
c=‘false’;
end
c
5
A=input(‘输入一个5*6矩阵A=’);
n=input(‘输入一个正整数n=’);
A
if n<=5&&n>0
disp(‘A的第n行元素为:’)
disp(A(n,:));
else
disp(‘错误!n超出矩阵行数!’)
disp(‘A的最后一行元素为:’)
disp(A(5,:));
end