I think I found a solution using a table
tbl = table(flatten(XY(:,:,1)),flatten(XY(:,:,2)),flatten(z));
Surfit = @(B,XY) B(1)*exp(B(2).*XY(:,1)) + (1 - exp(B(3).*XY(:,2)));
nlm = fitnlm(tbl,Surfit,[0.5 -0.5 -0.5],'Options',statset('Display','final','Robust','On'));
nlm.Coefficients{:,1}'
But they seem to provide quite different answers with these data as seen in the output of the updated code attached
Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.
B =
0.6343 -0.4053 -0.2029
Iterations terminated: relative change in SSE less than OPTIONS.TolFun
B =
0.6340 -0.4044 -0.2026
Iterations terminated: relative norm of the current step is less than OPTIONS.TolX
ans =
0.1564 -0.2730 -0.2366
Any comment on the discrepancies welcome.
Many thanks,
Patrick