defining fitting curve to measured data
3 次查看(过去 30 天)
显示 更早的评论
Hi, i try to find a fitting function for my measured data. Sadly i do not come to a good result. my last try was based on defining a fitting type. but i just get errors. the matrix distance_data contains the measurement results. in the first colum is stored the distance and the ones after are the measurment values. the value of the measurment results decrease by increasing distance. this means the measurement curve goes from high value at low distance and low measurment value at high distance. for this behavioure i am looking for a estimation method/ fitting function.
fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0],...
'Upper',[Inf,max(distance_data(:,1))],...
'StartPoint',[1 1]);
ft = fittype('(a/(x+b))^n','problem','n','options',fo);
fitobject = fit(distance_data(:,1),distance_data(:,material_index),'ft');
[curve2,gof2] = fit(distance_data(:,1),distance_data(:,material_index),ft,'problem',2)
[curve3,gof3] = fit(distance_data(:,1),distance_data(:,material_index),ft,'problem',3)
hold on
plot(curve2,'m')
plot(curve3,'c')
legend('Data','n=2','n=3')
hold off
by performing the code in this way i get following error:
>> fo = fitoptions('Method','NonlinearLeastSquares',...
'Lower',[0,0],...
'Upper',[Inf,max(distance_data(:,1))],...
'StartPoint',[1 1]);
ft = fittype('(a/(x+b))^n','problem','n','options',fo);
fitobject = fit(distance_data(:,1),distance_data(:,material_index),'ft');
Error using fittype>iCreateFromLibrary (line 414)
Library function ft not found.
Error in fittype>iCreateFittype (line 345)
obj = iCreateFromLibrary( obj, varargin{:} );
Error in fittype (line 330)
obj = iCreateFittype( obj, varargin{:} );
Error in fit>iFit (line 165)
model = fittype( fittypeobj, 'numindep', size( xdatain, 2 ) );
Error in fit (line 116)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
>>
do you have a idea what i am doing wrong ?
do you have another way to perform a curve fitting with the option to add some basic function (eg: y=1/x or y=cos(x))?
thanks in advance for your support !
1 个评论
Rik
2021-8-26
What happens if you try this?
fitobject = fit(distance_data(:,1),distance_data(:,material_index),ft);
回答(1 个)
Roshan Hingnekar
2021-9-2
编辑:Roshan Hingnekar
2021-9-2
Refer to the following documentation on How to fit a curve
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!