shortcut for simple if conditions.
The function works similar to Excel format.
First argument is the condition, second is what to do if true, third is what to do if false.
example 1:
A = ifelse(x>thr, 5, 3)
will execute:
if x>thr
A = 5
else
A = 3
end
example 2:
A = ifelse(im>thr, im*2, im/2)
will execute:
A = im*2 where im>thr
A = im/2 where im<=thr
example 3:
ifelse(x~=0, 'y=1/x;', 'disp ''x is zero''')
will execute:
if x~=0
y = 1/x;
else
disp 'x is zero'
end
引用格式
Yanai (2024). if-then-else shortcut (https://www.mathworks.com/matlabcentral/fileexchange/28587-if-then-else-shortcut), MATLAB Central File Exchange. 检索来源 .
MATLAB 版本兼容性
创建方式
R2008b
兼容任何版本
平台兼容性
Windows macOS Linux类别
- MATLAB > External Language Interfaces > .NET with MATLAB > Call .NET from MATLAB > .NET Data Types in MATLAB >
在 Help Center 和 MATLAB Answers 中查找有关 .NET Data Types in MATLAB 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!