I can understand why Matlab throws an error. str3
is undefined in your example but from your description, I can make that str3
was defined in your workspace and contained a string. At line 3, you made a function that is independent of x
that evaluates whatever str3
was before you executed line 3, every time g
is called. I think your line 3 does not reflect what you intended.
I think what you try to do is something along the lines:
g = @(x) eval(x);
g('x = zeros(3,3)')
But you haven't described what you aimed to achieve. Please provide more details.