How to store a function in a variable in MATLAB?
Let's say I want to store the function y(x) = x + 2 in a variable.
Is there any way to save y = x + 2, and access as y(x)? For example, y(2)?
An anonymous function is what you're looking for:
>> y = @(x) x+2; >> y(2) ans = 4