defining fitting curve to measured data

2 views (last 30 days)
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]);
Unrecognized function or variable 'distance_data'.
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 Comment
Rik
Rik on 26 Aug 2021
What happens if you try this?
fitobject = fit(distance_data(:,1),distance_data(:,material_index),ft);

Sign in to comment.

Answers (1)

Roshan Hingnekar
Roshan Hingnekar on 2 Sep 2021
Edited: Roshan Hingnekar on 2 Sep 2021
Refer to the following documentation on How to fit a curve
Also use the curve fitting toolbox for increased efficiency

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!