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!