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

2 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2014-6-23
编辑:Star Strider 2014-6-23
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 个评论
Veena
Veena 2014-6-23
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 2014-6-23
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile 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!

Translated by