if-then-else shortcut
by Yanai
30 Aug 2010
(Updated 31 Aug 2010)
The function is a shortcut for simple if conditions, to reduce redundant code
|
Watch this File
|
| File Information |
| Description |
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
|
| MATLAB release |
MATLAB 7.7 (R2008b)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Updates |
| 31 Aug 2010 |
added another option to function (example 2 in description).
|
| Tag Activity for this File |
| Tag |
Applied By |
Date/Time |
| if |
Yanai |
30 Aug 2010 13:36:05 |
| then |
Yanai |
30 Aug 2010 13:36:05 |
| else |
Yanai |
30 Aug 2010 13:36:05 |
| code |
Yanai |
30 Aug 2010 13:36:05 |
|
Contact us at files@mathworks.com