Error using fittype for custom function

조회 수: 10 (최근 30일)
Lorenz
Lorenz 2013년 10월 24일
댓글: Peter Reader 2016년 8월 8일
Hi I would like to fit a custom defined function (not continuous) to experimental time series data. My problem is that fittype does not accept my function although the function itself works fine and the syntax worked for similar functions. below you will find the fittype command I use, the error and the function that I would like to fit. Thank you in advance for any suggestions.
Lorenz
fittype command: ft1=fittype('Exp_delay_v2(t, tau1, tau2, a, b, dt1, dt2)','independent','t','coeff',{'tau1','tau2','a','b','dt1','dt2'});
Error using fittype>iCreateFittype (line 368) Expression Exp_delay_v2(t, tau1, tau2, a, b, dt1, dt2) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated: Error in fittype expression ==> Exp_delay_v2(t, tau1, tau2, a, b, dt1, dt2) ??? Index exceeds matrix dimensions.
function y = Exp_delay_v2(t, tau1, tau2, a, b, dt1, dt2)
y=zeros(size(t));
s = 10.8*200;
d1=dt1*200;
d2=dt2*200;
t1a = t(1:s-d2);
t1b = t(s-d2+1:2*s-d2+d1);
t2 = t(1:2*s-d1+d2);
y(1:s+d1) = ( (a+b) - b.*(1-exp(-(t1b)./tau2)) );
y(s+1+d1:3*s+d2) = ( a + b.*(1-exp(-(t2)./tau1)) );
y(3*s+d2+1:end) = ( (a+b) - b.*(1-exp(-(t1a)./tau2)) );

채택된 답변

Lorenz
Lorenz 2013년 10월 24일
Solved the problem. fittype tests the function with only 2 independent input values, which causes an error in my custom function. I used a very untidy solution, by giving a default output if the size of the dependent variable is too short.
Thanks for looking anyway!
  댓글 수: 1
Peter Reader
Peter Reader 2016년 8월 8일
Can you provide an exact solution to this? I have the same problem!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

ran
ran 2013년 10월 31일
Hi, I'm not sure I got what you meant. I want to have a custom function with many parameters, how should I do it?
  댓글 수: 1
Lorenz
Lorenz 2013년 10월 31일
I am not sure what you are looking for. Do you want to fit the parameters of the custom function? The documentation gives some good examples for that. Look for 'fit', 'custom function'. Lorenz

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by