use*_*243 1 matlab if-statement
假设我们if
在MATLAB中有这个声明:
if rn == 1 || rn == 2 || rn == 3 || rn == 4 || rn == 5
%% Some calculations
elseif rn == 6 || rn == 7 || rn == 8 || rn == 9 || rn == 10
%% Some calculations
end
Run Code Online (Sandbox Code Playgroud)
有什么方法可以缩短这个if
陈述吗?
您可以通过使用any
检查值向量来执行此操作:
if any(rn == 1:5)
%% Some calculations
else if any(rn == 6:10)
%% Some calculations
end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
60 次 |
最近记录: |