How to stop figure window from popping up.

14 Ansichten (letzte 30 Tage)
Milind Amga
Milind Amga am 4 Sep. 2021
Beantwortet: Sivani Pentapati am 29 Nov. 2021
I get a figure window popping up when I try to plot two graphs both on same gui window with two y-axes. Can anyone please tell me how can i stop figure window popping up. I am putting complete code below, please have a look. Thankyou for your time in advance.
classdef StaticPad_data < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
PLOTButtonGroup matlab.ui.container.ButtonGroup
TempratureButton matlab.ui.control.RadioButton
ThrustButton matlab.ui.control.RadioButton
BothButton matlab.ui.control.RadioButton
UIAxes matlab.ui.control.UIAxes
end
properties (Access = private)
Thrust
Time
Temprature
end
methods
function plotdata(app)
if app.TempratureButton.Value
xlabel(app.UIAxes,'Time');
ylabel(app.UIAxes,'Temprature')
title(app.UIAxes,'Temprature vs Time')
plot(app.UIAxes,app.Time,app.Temprature,'o-r');
elseif app.ThrustButton.Value
xlabel(app.UIAxes,'Time');
ylabel(app.UIAxes,'Thrust');
title(app.UIAxes,'Thrust vs Time');
plot(app.UIAxes,app.Time,app.Thrust,'*-k');
elseif app.BothButton.Value
hold(app.UIAxes,'on')
yyaxis left
xlabel(app.UIAxes,'Time');
ylabel(app.UIAxes,'Temprature');
plot(app.UIAxes,app.Time,app.Temprature,'o-r');
yyaxis right
ylabel(app.UIAxes,'Thrust');
title(app.UIAxes,'Thrust vs Time');
plot(app.UIAxes,app.Time,app.Thrust);
legend(app.UIAxes,'Temprature','Thrust','*-k');
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
all_data = data('all');
app.Thrust = all_data.thrust;
app.Temprature = all_data.temprature;
app.Time = all_data.time;
app.plotdata ;
end
% Selection changed function: PLOTButtonGroup
function PLOTButtonGroupSelectionChanged(app, event)
app.plotdata;
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Color = [0.6706 0.8431 0.9686];
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create PLOTButtonGroup
app.PLOTButtonGroup = uibuttongroup(app.UIFigure);
app.PLOTButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @PLOTButtonGroupSelectionChanged, true);
app.PLOTButtonGroup.Title = 'PLOT';
app.PLOTButtonGroup.FontWeight = 'bold';
app.PLOTButtonGroup.FontSize = 13;
app.PLOTButtonGroup.Position = [531 195 100 93];
% Create TempratureButton
app.TempratureButton = uiradiobutton(app.PLOTButtonGroup);
app.TempratureButton.Text = 'Temprature';
app.TempratureButton.FontWeight = 'bold';
app.TempratureButton.FontAngle = 'italic';
app.TempratureButton.Position = [2 47 87 22];
app.TempratureButton.Value = true;
% Create ThrustButton
app.ThrustButton = uiradiobutton(app.PLOTButtonGroup);
app.ThrustButton.Text = 'Thrust';
app.ThrustButton.FontWeight = 'bold';
app.ThrustButton.FontAngle = 'italic';
app.ThrustButton.Position = [2 26 65 22];
% Create BothButton
app.BothButton = uiradiobutton(app.PLOTButtonGroup);
app.BothButton.Text = 'Both';
app.BothButton.FontWeight = 'bold';
app.BothButton.FontAngle = 'italic';
app.BothButton.Position = [2 5 65 22];
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, {'X'; ''})
ylabel(app.UIAxes, 'Y')
zlabel(app.UIAxes, 'Z')
app.UIAxes.FontWeight = 'bold';
app.UIAxes.XGrid = 'on';
app.UIAxes.YGrid = 'on';
app.UIAxes.FontSize = 13;
app.UIAxes.Position = [1 18 489 447];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = StaticPad_data
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
  2 Kommentare
Walter Roberson
Walter Roberson am 4 Sep. 2021
You should plot() first and set labels after that. When an axes does not have "hold on" then plot() will clear the axes, which would remove the labels and titles you just put in.
Milind Amga
Milind Amga am 4 Sep. 2021
Bearbeitet: Milind Amga am 4 Sep. 2021
I tried what you told me but the figure window is still poping up. I want both graphs to be plotted in the gui window. How can I do that?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sivani Pentapati
Sivani Pentapati am 29 Nov. 2021
Hi Milind,
You are getting the second plot in the new figure because yyaxis adds second yaxis to the active axis. I assume a new axis is being created in the above case and hence the new figure. To ensure that the new axes are added to the UIAxes of App Designer, change the call to yyaxis into the below code where app.UIAxes are explicity mentioned for the axes.
elseif app.BothButton.Value
hold(app.UIAxes,'on')
yyaxis(app.UIAxes,'left');
xlabel(app.UIAxes,'Time');
ylabel(app.UIAxes,'Temprature');
plot(app.UIAxes,app.Time,app.Temprature,'o-r');
yyaxis(app.UIAxes,'right');
ylabel(app.UIAxes,'Thrust');
title(app.UIAxes,'Thrust vs Time');
plot(app.UIAxes,app.Time,app.Thrust);
legend(app.UIAxes,'Temprature','Thrust','*-k');
end

Kategorien

Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by