function f = choose(flag,yes,no) <flag> is a truth value (0 or 1) <yes> is something <no> is something if <flag>, return <yes>. otherwise, return <no>. example: isequal(cellfun(@(x) choose(isempty(x),2,x),{[] 1}),[2 1])
0001 function f = choose(flag,yes,no) 0002 0003 % function f = choose(flag,yes,no) 0004 % 0005 % <flag> is a truth value (0 or 1) 0006 % <yes> is something 0007 % <no> is something 0008 % 0009 % if <flag>, return <yes>. otherwise, return <no>. 0010 % 0011 % example: 0012 % isequal(cellfun(@(x) choose(isempty(x),2,x),{[] 1}),[2 1]) 0013 0014 if flag 0015 f = yes; 0016 else 0017 f = no; 0018 end