【问题标题】:surface(2d) fit in MATLAB with anonymous functionsurface(2d) 适合带有匿名函数的 MATLAB
【发布时间】:2013-08-16 02:04:05
【问题描述】:

我想在 MATLAB 中将fit 用于二维。 我单独定义了函数,然后用fittype调用它

x 有两列!

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

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

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

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

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

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

仍然有同样的问题。

我用fit -all

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

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

对我来说听起来毫无意义,因为我的 x 分为两列!!!!

然后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 方法

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

【问题讨论】:

  • 简单来说,你能告诉我如何定义适合类型的冲浪适合的匿名函数吗?

标签: matlab


【解决方案1】:

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

这是一个使用您的函数和使用字符串的 Franke 数据的示例:

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

这是一个使用匿名函数将您的函数与 Franke 数据结合使用的示例:

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

【讨论】:

    猜你喜欢
    • 2016-05-02
    • 1970-01-01
    • 2016-05-08
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多