matlabFunction() has generated for me AmplAndDers() to be used in fminunc(). The very first objective function evaluation fails:
Error using reshape
Number of elements must not change. Use  as one of the size inputs to automatically calculate the appropriate size for that dimension.
Error in AmplAndDers (line 93)
Hess = reshape([-t2.*t3.*t4. ... .*(3.0./4.0)],[4,4]);
The signature of the function is:
function [Ampl,GradA,Hess] = AmplAndDers(C1_0,C2_0,R1_0,R2_0,w,x1,x2,x3,x4)
I call it with a w being an array. Two other outputs are returned correctly. I do not understand what does the above suggestion mean:
Use  as one of the size inputs to automatically calculate the appropriate size for that dimension.
If I manually change the above reshape() call to end with:
the program runs OK.
How can avoid the manual intervention?