if-then-else shortcut

버전 1.1.0.0 (1.5 KB) 작성자: Yanai
The function is a shortcut for simple if conditions, to reduce redundant code
다운로드 수: 583
업데이트 날짜: 2010/8/31

라이선스 보기

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
카테고리
Help CenterMATLAB 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!
버전 게시됨 릴리스 정보
1.1.0.0

added another option to function (example 2 in description).

1.0.0.0