转移我自己的乐趣到nlinfit

时间:2014-03-16 11:11:44

标签: matlab function regression

通常,nlinfit看起来像

nlinfit(X,Y,modelfun,beta0)

modelfun取决于XY。我有一个函数f,它依赖于常量矩阵(在使用nlinfit之前生成):

function [value] = f(X,Y,Matr)

如何准确地将f转移到nlinfit

1 个答案:

答案 0 :(得分:1)

您想使用匿名函数:

%# define Matr here
Matr = rand(3); %# e.g. 3x3 double array with random numbers

%# define the anonymous function to pass to nlinfit
%# @ signals an anonymous function
%# (x,y) are the two inputs the function takes
%# f(x,y,Matr) is the function that is called with variable x,y
%# and constant Matr as defined in the workspace at the moment
%# modelfun gets defined.
modelfun = @(x,y)f(x,y,Matr);

%# call nlinfit
result = nlinfit(X,Y,modelfun,beta0);