1
votes

I want to use fit in MATLAB for two dimensions. I defined function separately and then called it with fittype

x has two columns!

f=fittype('@(x)myfun(beta1, beta2,beta3, x)')

and then customize in options my start point and algorithm.

then use [results, goodness]=fit(x, zdata,f, options), but I have a error

??? Too many inputs to FITTYPE function.

Error in ==> fit at 443 errstr = handleerr( errid, errmsg, suppresserr );

I also tried with [results, goodness]=fit([x(:,1), x(:,2)], zdata,f, options),

and still have the same problem.

I used fit -all

XDATA must be a matrix with one to two columns.

Error in ==> fit at 115 errstr = handleerr('curvefit:fit:xDataMustBeColumnVector', ...

for me sounds meaningles , since I have my x in two columns!!!!

and then which fit -all

/Applications/matlab/MATLAB_R2010a.app/toolbox/curvefit/curvefit/fit.m /Applications/matlab/MATLAB_R2010a.app/toolbox/stats/@ProbDistUnivParam/fit.m % ProbDistUnivParam method /Applications/matlab/MATLAB_R2010a.app/toolbox/stats/@NaiveBayes/fit.m % NaiveBayes method /Applications/matlab/MATLAB_R2010a.app/toolbox/stats/@gmdistribution/fit.m % gmdistribution method

could you please help me to use fit and fittype to fit my 2 dimension data? {please don't introduce me meshgrid and other commands.}

1
just in a simple way, could you tell me how to define anonymous function for surf fit with fit type? - user1331843

1 Answers

1
votes

You need to add the parameter 'numindep' = 2 which indicates that your fit is for a surface (i.e has two independent variables).

Here's an example using your function with the Franke data using a string:

load franke
ft = fittype('myfun(beta1, beta2, beta3, [x, y])', 'numindep', 2)
[results, goodness] = fit([x, y], z, ft)

Here's an example using your function with the Franke data using an anonymous function:

load franke
ft = fittype(@(beta1,beta2,beta3, x, y)myfun(beta1, beta2,beta3, [x, y]), 'numindep', 2)
[results, goodness] = fit([x, y], z, ft)