通常,nlinfit
看起来像
nlinfit(X,Y,modelfun,beta0)
modelfun
取决于X
和Y
。我有一个函数f
,它依赖于常量矩阵(在使用nlinfit
之前生成):
function [value] = f(X,Y,Matr)
如何准确地将f
转移到nlinfit
?
答案 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);