A problem using the app designer
2 views (last 30 days)
Abolfazl Chaman Motlagh on 8 Dec 2021
in PlotFitButtonPushed function which you plot your graphs, by using figure you create new figure out of your app.UIFigure. use axes(app.UIAxes) to select the Axes in app as current Axes. or just add Axes to plot.
function PlotFitButtonPushed(app, event)
% Create a new vector that starts at 0 and goes
% up to 7 in steps of 0.5. Assign to a column vector voltage_fit.
app.voltage_fit = 0:0.5:7;
app.voltage_fit = app.voltage_fit';
% Create a new vector, displacement_fit, for the line of
% best fit. It should be a column vector the same length as voltage_fit
% found using the calibration equation.
app.displacement_fit = polyval(app.coeffs, app.voltage_fit);
% Plot the measured displacement against voltage that came from
% the file, and the modelled line of best fit on the same figure.
% Label appropriately.
% or just plot(app.voltage, app.displacement) because you make
% app.UIAxes curent Axes
% or just hold on
legend('Raw data', 'Line fit')
More Answers (1)
Peter Bonavita on 8 Dec 2021
I understand your app generates a plot, but the plot appears in a figure outside the app. In your app's call to plot, you can specify the axis where you want the plot to appear.
Check out lines 70-71 of the .MLAPP file from this example. You can open the app using this command, then view the code shown below in the code view:
Here's the code, in this case it shows the plot targets the axis at app.PrincipalInterestUIAxes
% Plot the principal and interest
I wasn't able to reproduce using your app but it looks like you'll just need to add app.UIAxes in your calls to plot, something like:
plot(app.UIAxes, app.voltage, app.displacement)
Hope this helps,