-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiff.m
More file actions
29 lines (25 loc) · 657 Bytes
/
iff.m
File metadata and controls
29 lines (25 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
% Ternary operator for matlab
%
% output = iff(condition, whentrue, whenfalse)
%
%
%
function output = iff(condition, whentrue, whenfalse)
narginchk(3,3);
nc = length(condition);
nt = length(whentrue);
nf = length(whenfalse);
condition = logical(condition);
if nc == 1
if condition
output = whentrue;
else
output = whenfalse;
end
elseif nc == nt && nc == nf
output(condition) = whentrue(condition);
output(~condition) = whenfalse(~condition);
else
error('if condition is nonscalar, all arguments must be of same size');
end
end