本文介绍了surface(2d)适用于具有匿名功能的MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MATLAB中将fit用于两个维度.我分别定义了函数,然后用fittype

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

x有两列!

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

然后在选项中自定义我的起点和算法.

and then customize in options my start point and algorithm.

然后使用[results, goodness]=fit(x, zdata,f, options),但出现错误

??? FITTYPE函数的输入过多.

??? Too many inputs to FITTYPE function.

==>中的错误适合443 errstr = handleerr(errid,errmsg,inhibitorr);

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

我也尝试了[results, goodness]=fit([x(:,1), x(:,2)], zdata,f, options)

并且仍然有相同的问题.

and still have the same problem.

我使用了fit -all

XDATA必须是一到两列的矩阵.

XDATA must be a matrix with one to two columns.

==>中的错误适合115 errstr = handleerr('curvefit:fit:xDataMustBeColumnVector',...

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

对我来说听起来很有意义,因为我将x分为两列!!!

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

,然后which fit -all

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

/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

能否请您帮助我使用fitfittype来拟合我的2维数据?{请不要向我介绍meshgrid和其他命令.}

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.}

推荐答案

您需要添加参数'numindep' = 2,该参数指示您的拟合是针对曲面的(即具有两个自变量).

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

下面是使用函数和字符串的Franke数据的示例:

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)

以下是使用匿名函数将函数与Franke数据一起使用的示例:

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)

这篇关于surface(2d)适用于具有匿名功能的MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 07:04