How do I use the curve fitting tool with a custom function that does not depend of x?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I always get an error in the toolbox when I try to fit to a Matlab function I have. I have a set of points to which I want to fit some data. Problem is, the points are, for example, for x=1.4, 2.5, 4.1,... , and the data I have is for x=1, 2, 3,... , yet the way this data is calculated does not dependent of the value of x, even though each individual data point is assigned to x=1, 2, 3,.... I think that the fact that it does not depend of x must be the problem, since when I use this function and just assign some values to the parameters f1,f2,f3,f4,f5,a,b,c,d I obtain a fit (though wrong unless I am able to manually fit the parameters).
If I just use fit(f1,f2,f3,f4,f5,a,b,c,d) as the custom equation I get the error:
"The independent variable x does not appear in the equation expression."
And I use fit(f1,f2,f3,f4,f5,a,b,c,d,x) I get:
"Expression fit(f1,f2,f3,f4,f5,a,b,c,d,x) is not a valid MATLAB expression, has non-scalar coefficients, or cannot be evaluated"
What could be the problem? The function I have is as follows:
function f=fit(f1,f2,f3,f4,f5,a,b,c,d)
x=(1:(size(stopProb,2)-1))';
sum1=1:(size(stopProb,2)-1);
sum2=1:(size(stopProb,2)-1);
sum3=1:(size(stopProb,2)-1);
sum4=1:(size(stopProb,2)-1);
sum5=1:(size(stopProb,2)-1);
for i=2:size(stopProb,2)
sum1(i-1)=sum(stopProb(1:a,i));
sum2(i-1)=sum(stopProb(a+1:b,i));
sum3(i-1)=sum(stopProb(b+1:c,i));
sum4(i-1)=sum(stopProb(c+1:d,i));
sum5(i-1)=sum(stopProb(d+1:size(stopProb,1),i));
end
v=[sum1;sum2;sum3;sum4;sum5];
sumTotal=v';
probInterval=zeros(size(sumTotal,1),2);
f_dia_fit=zeros(size(sumTotal,1),1);
for u=1:size(sumTotal,1)
probInterval(u,1)=sumTotal(u,1)/(sumTotal(u,1)+sumTotal(u,2)+sumTotal(u,3)+sumTotal(u,4)+sumTotal(u,5));
probInterval(u,2)=sumTotal(u,2)/(sumTotal(u,1)+sumTotal(u,2)+sumTotal(u,3)+sumTotal(u,4)+sumTotal(u,5));
probInterval(u,3)=sumTotal(u,3)/(sumTotal(u,1)+sumTotal(u,2)+sumTotal(u,3)+sumTotal(u,4)+sumTotal(u,5));
probInterval(u,4)=sumTotal(u,4)/(sumTotal(u,1)+sumTotal(u,2)+sumTotal(u,3)+sumTotal(u,4)+sumTotal(u,5));
probInterval(u,5)=sumTotal(u,5)/(sumTotal(u,1)+sumTotal(u,2)+sumTotal(u,3)+sumTotal(u,4)+sumTotal(u,5));
f_dia_fit(u,1)=probInterval(u,1)*f1+probInterval(u,2)*f2+probInterval(u,3)*f3+probInterval(u,4)*f4+probInterval(u,5)*f5;
end
f=f_dia_fit;
4 Kommentare
Walter Roberson
am 24 Mär. 2019
Think of using t as the independent variable if that helps.
The first time step, t=1, you get a value which happens to be stored in y(1)
The second time step, t=2, (a fixed interval later), you get a value which happens to be stored in y(2)
The third time step, t=3, (the fixed interval after the second), you get a value which happens to be stored in y(3)
and so on.
It does not matter that you have no literal 'x' or 't' in your sequence of values: it only matters that they represent function values at consistent step size. In such a case, you can use the index as your independent variable. x = 1 : length(y) is fine.
Antworten (1)
Siehe auch
Kategorien
Mehr zu Fit Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!