Skip to content

Instantly share code, notes, and snippets.

@Thermoflux
Last active August 17, 2019 19:46
Show Gist options
  • Save Thermoflux/d48e8bd7e48cf9e29561383e16eb01f6 to your computer and use it in GitHub Desktop.
Save Thermoflux/d48e8bd7e48cf9e29561383e16eb01f6 to your computer and use it in GitHub Desktop.
A simple ifelse anonymous MATLAB function similar to R's ifelse
%%ifelse - Single line ifelse alternative statement for Matlab. Its implemented as an anonymous function for low overhead.
%% This will only work for numerical values, Please use with caution.
ifelse = @(Condition,TrueVal,FalseVal) Condition .*TrueVal + ~Condition .*FalseVal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment