質問

As usually, nlinfit looks like

nlinfit(X,Y,modelfun,beta0)

where modelfun depends on X and Y. I have a function f, which depends on constant matrix (generated before using nlinfit):

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

How to transfer f to nlinfit accurately?

役に立ちましたか?

解決

You want to use an anonymous function:

%# 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);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top