My code that plots and fits a distribution onto data works for me but errors for others?
Show older comments
My code inputs a data file, filters that data, and plots the data with a trendline. It works fine for me, but my mentor is getting error messages like the following. I have no clue as to why. Thanks.
>> filterAndPlot
Error using fit>iFit (line 367)
Undefined function 'optimset' for input arguments of type 'struct'.
Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
Error in createFit (line 29)
[fitresult, gof] = fit( xData, yData, ft, opts );
Error in filterAndPlot (line 22)
createFit(arrivalTime, velocity)
My code is below. The function createFit.m must be included in the active folder.
[num,txt,raw] = xlsread('LS174TPselectin-2.xlsx'); %read data
row_idx = ((num(:,25)>200 & num(:,27)>2 & num(:,28)>400 & num(:,29)<300 & num(:,30)>7 & num(:,32)<50)...
&(num(:,25)>200 & num(:,27)>2 & num(:,28)>400) & num(:,29)<300 & num(:,30)<30 & num(:,32)<50); % filter data
num_filtered = num(row_idx,:); %applying row indices
arrivalTime = num_filtered(:,25); %extracting x data
velocity = num_filtered(:,29); %extracting y data
createFit(arrivalTime, velocity)
[xData, yData] = prepareCurveData( arrivalTime, velocity );
ft = fittype( 'power1' ); %power law curve fitting
opts = fitoptions( ft );
opts.Display = 'Off';
opts.Lower = [-Inf -Inf];
opts.StartPoint = [9843.82221551625 -0.758786133796217];
opts.Upper = [Inf Inf];
[fitresult, gof] = fit(xData, yData, ft, opts);
gof %goodness of fit info
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!