1.matlab里的 不等于 表示:~=
>> rem(4,2)
% remainder 求4对2的余数
ans =
0
2.if elseif else 语句:
a = 3;
if rem(a, 2) == 0
disp('a is even');
else
disp('a is odd');
end
3.switch case 语句:
input_num = 1;
switch input_num
case -1
disp('negative 1');
case 0
disp('zero');
case 1
disp('positive 1');
otherwise %% 还有otherwise!
disp('other value');
end
n = 1;
while prod(1:n)

本文介绍了MATLAB中的不等于运算符~=,以及if-elseif-else和switch-case语句的使用。后续内容涵盖了课后练习,如计算阶乘、数值转换、函数定义、控制流程和数据处理。此外,还讲解了break语句的应用和函数参数检查(nargin和nargout)。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



