I am using STR2FUNC to construct a function handle from a string and I would like to pass a workspace variable as a parameter to the function. In the below example I expect the fcn2 to behave in the same way as fcn1:
a = 1;fcn1 = @(x) x+a;fcn2 = str2func('@(x) x+a');fcn1(1)fcn2(1)
However I am receiving the following error:
??? Undefined function or variable 'a'. Error in ==> @(x)x+a
Best Answer