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
0 个评论
采纳的回答
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 个评论
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 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!