App Designer UIAxes doesn't show results of fitting curve

조회 수: 6 (최근 30일)
Marcello
Marcello 2016년 3월 22일
댓글: Marcello 2016년 3월 23일
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에서 Smoothing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by