Debugger running different code than normal runner

Hello, I've been using app designer to try and create a UI for some analysis that we're currently doing. When I try to change the axes/plot positions, it works when I run it using debug mode, but it does not work when I run it normally.
I was able to recreate it with a simple test case.
Adding two axes in a simple grid layout (image 1) with the following code (image 2):
app.UIAxes.Position = [100 150 200 300];
app.UIAxes2.Position = [300 350 400 500];
If I were to put a breakpoint on the first line, press run and then continue, the results are what is expected with the graphs out of place (image 3). However, if I were to run it without any breakpoints, the runner treats it as if the code wasn't there (image 4). I was wondering if someone could help me get it to work normally, without having to use breakpoints to work around this bug.
Image 1
image 2
image 3
image 4

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 8 月 30 日
移動済み: Steven Lord 2022 年 8 月 31 日

0 投票

Add a drawnow() ?

5 件のコメント

Steven Lord
Steven Lord 2022 年 8 月 31 日
That was my first thought as well. The reason that your code running in debug mode may not need a drawnow is, I believe, related to the More About section on the documentation page for the drawnow function.
"These actions are equivalent to calling a full drawnow command:
I believe reaching the debug prompt K>> counts as the first bullet.
Walter Roberson
Walter Roberson 2022 年 8 月 31 日
Technically, debugger counts as using keyboard() , which is why the prompt is K>>
Mingda He
Mingda He 2022 年 8 月 31 日
Hello, I tried adding the drawnow() function, as well as adding these lines to a separate function thats called at the end of every callback, but it still doesn't work. Is there another function that might work?
app.graphSSWT.Position = [66 284 524 238];
app.graphWaves.Position = [150 280 524 500];
drawnow();
Thanks for the help!
Walter Roberson
Walter Roberson 2022 年 8 月 31 日
please post the code for testing... my version of MATLAB cannot execute pictures of code.
Mingda He
Mingda He 2022 年 9 月 1 日
classdef test < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
GridLayout matlab.ui.container.GridLayout
UIAxes2 matlab.ui.control.UIAxes
UIAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.UIAxes.Position = [100 150 200 300];
app.UIAxes2.Position = [300 350 400 500];
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.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create GridLayout
app.GridLayout = uigridlayout(app.UIFigure);
app.GridLayout.ColumnWidth = {'1x'};
% Create UIAxes
app.UIAxes = uiaxes(app.GridLayout);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
zlabel(app.UIAxes, 'Z')
app.UIAxes.Layout.Row = 1;
app.UIAxes.Layout.Column = 1;
% Create UIAxes2
app.UIAxes2 = uiaxes(app.GridLayout);
title(app.UIAxes2, 'Title')
xlabel(app.UIAxes2, 'X')
ylabel(app.UIAxes2, 'Y')
zlabel(app.UIAxes2, 'Z')
app.UIAxes2.Layout.Row = 2;
app.UIAxes2.Layout.Column = 1;
% 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 = test
% 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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

リリース

R2022a

質問済み:

2022 年 8 月 30 日

コメント済み:

2022 年 9 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by