MATLAB: Parfor: using eval with @()

anonymous functionevalforMATLABParallel Computing Toolboxparfor

Hi,
I want to rewrite a for loop into a parfor loop.
In the loop I call a function
[y,x] = outer_function(z1,z2,x...);
Within this function, the following bit of code causes an error message when used in the parfor loop ("Unexpected Matlab expression"):
f_handle = eval(['@(x)',inner_function_string,'(z1,z2,x)']);
inner_function_string is a string that refers to different functions that may be called. f_handle is used later on in outer_function.
If I use
f_handle=@(x)inner_function(z1,z2,x)
it works.
I know that eval can only be used within a function in parfor for transparency reasons. That's what outer_function() is for. So what may be my problem here?
Thanks for your help,
Svenn

Best Answer

I would suggest constructing the string and displaying it before eval()'ing it, to make sure that it contains what you think it should.