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
댓글 수: 0
채택된 답변
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
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Smoothing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!