Hi,
I am having some trouble with autoloading the Curve Fitting Toolbox with initial guesses and upper/lower bounds.
WHAT I HAVE DONE:
I performed a fit and generated the code. Part of it is shown below:
function [fitresult, gof] = createFit(x, y)
% Comments Removed for brevity
%% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'equation removed for brevity', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( ft );
opts.Display = 'Off';
opts.Lower = [0 0 0 Inf Inf 11.45 11.9 9.5 0 0 0];
opts.StartPoint = [0.0758542895630636 0.0539501186666072 0.530797553008973 0.779167230102011 0.934010684229183 11.59 12 10.4 0.2 0.2 0.455];
opts.Upper = [Inf Inf Inf Inf Inf 11.7 12.1 11.5 0.3 0.3 Inf];
ex = excludedata( xData, yData, 'Indices', [1 2 3 4 5......numbers reduced for brevity.....200] );
opts.Exclude = ex;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
X
REASON FOR AUTOSTARTING:
I had to repeat this fit for other data with the same initial guesses, fitting function and upper/lower bounds. As you can see from the last 2 lines, I had to manually select the points that I wanted to exclude. I wanted to avoid this timeconsuming procedure and instead open up the cftool with the exclusion already applied (i.e. with the excluded points already removed). To do this I used:
outliers = excludedata(xdata,ydata,'domain',[16 199]); % exclusion range may not make much sense.....just ignore it
cftool( xdata(~outliers),ydata(~outliers))
and it produced the desired result. The cftool opened up and the excluded points were removed from the graph.
PROBLEM:
I then wanted to take this one step further. I had to repeat this fit for other data with the same fitting function (it is a custom equation that is quite long, which is why I removed it from the text above), initial guesses, lower and upper bounds. So I decided to enter the custom equation (into ft), initial guesses, lower bounds and upper bounds as follows (from the command line, by copying and pasting the generated code from above):
ft = fittype( 'equation removed for brevity', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( ft );
opts.Display = 'Off';
opts.Lower = [0 0 0 Inf Inf 11.45 11.9 9.5 0 0 0];
opts.StartPoint = [0.0758542895630636 0.0539501186666072 0.530797553008973 0.779167230102011 0.934010684229183 11.59 12 10.4 0.2 0.2 0.455];
opts.Upper = [Inf Inf Inf Inf Inf 11.7 12.1 11.5 0.3 0.3 Inf];
I then saved the script file that I was using and entered this:
cftool( xdata(~outliers),ydata(~outliers), ft, opts)
but it did not produce the desired result. The cftool opened up as before and the excluded points were again excluded as I indicated, but this time a message came up saying the following:
Invalid inputs to CFTOOL
Input must be numeric with two or more elements.
Ignoring Zdata because itis not numeric
Ignoring Weights because it is not numeric
Only the exclusion statement was executed. I know this because, like before, the excluded data was not plotted.
I also tried:
cftool( xdata(~outliers, ft, opts),ydata(~outliers, ft, opts))
But it did not work either.
QUESTION:
Is there some way that I can specify the custom fitting equation, initial guesses, lower and upper bounds from the command line similar to how I specified the exclusion range? How should I modify the cftool command to automatically load up cftool with the custom fitting equation, initial guesses, lower and upper bounds entered?
NOTE: I do not want to perform command line curve fitting. I want to use the cftool GUI (to visualize the fits, as I change the parameters in realtime), so I need to start it up, but I need to start it up with the custom fitting equation, initial guesses, lower and upper bounds entered.
