Can you set the name for a fit when you call the cftool(x,y) gui?

18 views (last 30 days)
I'm fitting a large number of curves manually from an existing data set (essentially I have them plotted and am going through and looking visually for candidates for power law fits, sometimes only small segments of plots). My code then rips the data out from the existing figure (visible ones only), does some other processing, then dumps the x,y data to the curve fitting toolbox so I can look at/exclude/fit regions depending on how they look (they are not simply straight lines, and the exclusion region changes dynamically each time so its not easy to fit from the command line).
Anyway, all I would like to be able to do is set the fit name at the command line as I add each fit to the gui, but I can't figure out how. Or if it's even possible, I remember searching a few months back, but I just gave up and did it by hand. As there are dozens of sets to fit and the names are a bit convoluted it'd be nice to have a quicker way to do it.

Accepted Answer

David Sanchez
David Sanchez on 2 Sep 2013
You can not do it with cftool, but you can code it instead usign fit, like this:
Fit = 'my_fit';
[xData, yData] = prepareCurveData( x, y ); % x/y is your data
% Set up fittype and options.
ft = fittype( 'poly1' ); % choose a different type i
opts = fitoptions( ft );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', Fit );
h = plot( fitresult, xData, yData );
legend( h, 'y vs. x', Fit, 'Location', 'NorthEast' );
% Label axes
xlabel( 'x' );
ylabel( 'y' );
grid on
  1 Comment
Shawn
Shawn on 3 Sep 2013
Thanks for the response David. Unfortunately, I can't do the fit that way as most of each set is highly nonlinear (on a log log scale), and I only need to fit a (different!) region of each, which is why I'm doing it visually in the gui. I agree that otherwise that would be the best approach, and I have done so in the past for other data. If I can't name them individual this way, so be it.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!