choose.m 314 B

123456789101112131415161718
  1. function f = choose(flag,yes,no)
  2. % function f = choose(flag,yes,no)
  3. %
  4. % <flag> is a truth value (0 or 1)
  5. % <yes> is something
  6. % <no> is something
  7. %
  8. % if <flag>, return <yes>. otherwise, return <no>.
  9. %
  10. % example:
  11. % isequal(cellfun(@(x) choose(isempty(x),2,x),{[] 1}),[2 1])
  12. if flag
  13. f = yes;
  14. else
  15. f = no;
  16. end