Pass curvefit start points into function
조회 수: 1 (최근 30일)
이전 댓글 표시
I am new to Matlab, but have somehow figured out how to create a curve fitting function that is called by the main program. I need to curve fit many sets of data. The function has the following line of code:
opts.StartPoint = [226 26 1E07 0.4];
The points are currently hard coded, but I would like to pass into the curve fitting function a set of 4 starting points for each data set. The main routine will figure out the values of the four starting points and then I would like to pass these starting points in to the function.
The function is called from the main routine as follows:
[fitresult gof]=createFit(z,y);
댓글 수: 0
채택된 답변
Voss
2021년 12월 27일
You can add an additional input argument to your createFit function:
function [fitresult gof] = createFit(z,y,startPoint) % use your existing input and output variable names
% your code
end
You can make it an optional argument by checking whether it was given, and if not, use the default:
function [fitresult gof] = createFit(z,y,startPoint) % use your existing input and output variable names
if nargin < 3
startPoint = [226 26 1E07 0.4]; % whatever default value
end
% your code
end
Then call createFit with 2 or 3 arguments:
[fitresult gof] = createFit(z,y); % no startPoint specified -> createFit will use the default defined in its function definition
[fitresult gof] = createFit(z,y,[226 26 1E07 0.4]); % explicitly using default startPoint -> same as no startPoint specified
[fitresult gof] = createFit(z,y,[0 0 0 0]); % using some other startPoint
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!