MATLAB: Undefined Function Error when Calling MATLAB function containing a parfor loop via API for Python

matlab apiparforpythonundefinedfunction error

I receive an UndefinedFunction error for the sliced output variable: 'fvalsT' when calling the function 'PyModelFit' via Python. All directories are correct, and when called from the Matlab command window, the parfor loop executes as expected. As seen in the code below, the 'fvals' variables are properly initialized. This error only seems to occur when utilizing the integration with Python.
I am currently using Python 3.5.2. Thank you for any assistance in identifying the problem!
function [solution,solFlag,AIC,solutionset] = PyModelFit(subjchoices,selectOptions,fmins)
fvalsT = zeros(1,fmins);
fvalsO = zeros(1,fmins);
fvalsG = zeros(1,fmins);
fvalsE = zeros(1,fmins);
fvalsTT = zeros(1,fmins);
solsTDiscount = cell(1,fmins);
solsObj = cell(1,fmins);
solsG = cell(1,fmins);
solsExp = cell(1,fmins);
solsTT = cell(1,fmins);
TempDiscountMLE = @(x)TimeVaryTempDiscountMLE(x,subjchoices,selectOptions);
parfor n = 1:fmins %parallelize
gamma0 = 0.1*rand(1);
beta0 = 0.1*rand(1);
x0 = [gamma0,beta0];
[sol,fval] = fminsearch(TempDiscountMLE,x0);
fvalsT(n) = fval;
solsTDiscount(n) = {sol};
end
id_Temp = find(fvalsT == min(fvalsT));
...
...

Best Answer

For those who come across this problem, I believe it's been solved. It's related to the int64 par-for bug as outlined in this answer thread: https://www.mathworks.com/matlabcentral/answers/363559-parfor-fails-with-loop-indices-being-uint64