MATLAB学习——常用语句
if语句
if end
n = input('n=');
if rem(n,2) == 0
A = 'even'
end
if else
n = input('n='); #输入空数组判断为odd
if rem(n,2) == 0
A = 'even'
else
A = 'odd'
end
if elseif
n = input('n=');
if rem(n,2) == 0;
'even'
elseif rem(n,2) == 1;
'odd'
else
'empty'
end
switch语句
if语句判断分支可以用表达式,switch语句是枚举
n = input('n=')
switch rem(n,2);
case 1
'odd'
case 0
'even'
otherwise
'empty'
end