Fitting (X,Y) data with a function F of X, parameters A, and which is also a fucntion of a vector Z as input

1 view (last 30 days)
Hello
I face a problem with fit and fittype. I have (X,Y) data which I would like to fit with a function F(X,A,Z) where A is a vector of parameters, and Z is a vector whose dimensions equals those of X and Y.
I define F as an external function and Z is a global variable (but things are not different if I pass it as a parameter in the definition of F). If I use feval (or any other equivalent command) I can calculate: YF=F(X,A) and the resulting YF is correct.
Instead, when I use the command: ffun=fittype('F(x,a1,a2,a3,a4,a5)','independent','x','coefficient',{'a1','a2','a3','a4','a5'}); I got the error: " ??? Error using ==> fittype.fittype>fittype.fittype at 477 Expression F(x,a1,a2,a3,a4,a5) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated: Error in fittype expression ==> F(x,a1,a2,a3,a4,a5) ??? Matrix dimensions must agree. "
apparently this is due to the fact that fittype passes a dummy vector "x" to F, whose dimensions are (2,1) and values (0.3333 0.6667). But this vector "x" has different dimensions of the "real" vector X and, most importantly, of Z. Then the command crashes as the two vector dimensions do not agree.
Does anyone have any idea on how to solve this issue?
Thank you in advance for your help, simone

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!