MATLAB: Variable to executable code

dynamically generated codeMATLAB

Is it possible to change the value of a variable to text and then execute that text as code?
for example, if I have two different functions, function1(t) and function2(t), and I have a variable x that can take on the values {1,2}, would it be possible to do something like
Y = function'num2code(x)'(t)
where 'num2code(x)' (an expression that I'm just making up) is evaluated as a text '1' or '2' and then executed as part of the code in order to call the appropriate function.
In other words I am looking for dynamically generated code. I realize that I could accomplish the same thing with a series of 'if' statements, but in my case it would make the code very verbose and difficult to maintain.

Best Answer

doc feval
Related Question