Simplify fit function in MATLAB with handle

时间:2016-04-04 17:41:31

标签: matlab curve-fitting function-handle

I want to fit some data with MATLAB but my fit-function is pretty large and I just want to put it into pieces of functions.

At first I just tried it like

p1_prime = @(x,p) ...
p2_prime = @(x,p) ...

Then I put it into my model function

mod = D*exp(-p1_prime) + D*(-p2_prime)

Is there a simple way to do this?

1 个答案:

答案 0 :(得分:0)

The first step, generating the mod function, just needs some syntax help:

%Instead of this
mod=D*exp(-p1_prime)+D*(-p2_prime)

%Use this
mod = @(x,p) D*exp( -p1_prime(x,p) )+D*( -p2_prime(x,p) )

Function handle operations are not overloaded as required for your initial line of code to work.

In terms of getting this into a curve fitting routine, we'd need to see more about what you are trying to do.