App Designer UIAxes doesn't show results of fitting curve
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Marcello
am 22 Mär. 2016
Kommentiert: Marcello
am 23 Mär. 2016
Hi, I have generated an app in Guide which uses three different axis to show three different fit models for the same dataset (x,y). I ma trying now to recreate the same code with App design. The functions I am using are the same and the dataset is imported from Excel files. the problem I am facing is that in App Designer I can't plot x, y and the fit results as I do in GUIDE. Not sure if I am doing something wrong or simply is not possible. The code is as follows:
app.x = data(:,1);
app.x(isnan(app.x))=[];
app.y = data(:,2);
app.y(isnan(app.y))= [];
ylog = log((min(app.y)-app.y)+0.01);
mdl = polyfit(app.x,ylog,1);
b = mdl(:,1);
a = -min(app.y);
c = max(app.y);
ft =fittype('a*exp(-b*x)+c', 'independent', 'x', 'dependent', 'y');
opts =fitoptions ('Method', 'NonlinearLeastSquare');
opts.display = 'Off';
opts.StartPoint = [a b c];
opts.MaxFunEvals = 1200;
opts.MaxIter = 800;
[res, gof ] = fit( app.x, app.y, ft, opts);
plot(app.UIAxes, app.x, app.y, 'ro')
eq = ['y= ',num2str(res.a), '*exp(-' num2str(res.b) '*RR)+ ' num2str(res.c)];
app.Label3.Text = eq;
app.Label4.Text = ['a = ',num2str(res.a)];
app.Label5.Text = ['b =- ',num2str(res.b)];
app.Label6.Text = ['Rsquare = ',num2str(gof.rsquare)];
if I try to plot res, the error I get is : Non-numeric data is not supported in 'UIAxes'
Any help would be much appreciated
Best Regards Marcello
0 Kommentare
Akzeptierte Antwort
Mike Garrity
am 22 Mär. 2016
UIAxes has a number of limitations in this first release. From the error message, I would guess that either app.x or app.y is a datetime or duration. In R2016a, plotting into UIAxes doesn't support those, and you'll have to convert them to numerics with something like datenum.
5 Kommentare
Mike Garrity
am 22 Mär. 2016
Oh, got it. You're getting the plot method on the fit class, not the regular plot function. No UIAxes doesn't work with that. You'd need to have the fit class generate a list of points and then plot that:
load census;
f=fit(cdate,pop,'poly2');
x = 1700:2000;
y = feval(f,x);
plot(uiaxes,x,y)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Smoothing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!