App Designer UIAxes doesn't show results of fitting curve

6 次查看(过去 30 天)
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

采纳的回答

Mike Garrity
Mike Garrity 2016-3-22
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 个评论
Mike Garrity
Mike Garrity 2016-3-22
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)
Marcello
Marcello 2016-3-23
Thank you, that was helpful. I think I will keep on working with GUIDE for this project.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by