App Designer UIAxes doesn't show results of fitting curve
13 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Mike Garrity
on 22 Mar 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.
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!