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

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.

 채택된 답변

David Sanchez
David Sanchez 2013년 9월 2일
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

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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

질문:

2013년 8월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by