How to stop figure window from popping up.
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2021-9-4
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.
回答(1 个)
Sivani Pentapati
2021-11-29
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!