My code that plots and fits a distribution onto data works for me but errors for others?

1 view (last 30 days)
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

Star Strider
Star Strider on 23 Jun 2014
Edited: Star Strider on 23 Jun 2014
Does your mentor have the Curve Fitting Toolbox?
If your mentor has the Statistics Toolbox, you might consider rewriting your code to use the Statistics Toolbox function nlinfit instead. (You can also use fminsearch with an extra line or two of code.)
  2 Comments
Veena
Veena on 23 Jun 2014
Thank you! I will try that. Would you happen to know why my mentor might be getting these error messages though?
Star Strider
Star Strider on 23 Jun 2014
My pleasure!
My initial thought is that your mentor does not have the Curve Fitting Toolbox, so your calls to those functions on your mentor’s system throw errors because the functions don’t exist there.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!