Matlab 2016b - Maximizing affects pause

1 view (last 30 days)
Thomas H
Thomas H on 27 Sep 2017
Answered: Yair Altman on 29 Sep 2017
Hey together.
in a team project, I defined a global class, which includes the following code to maximize an app:
function win = getWindow(uiFig) %uiFig is the app's outer UIFigure
pause(0.1); %without this line accessing the controller leads to an error
figProps = struct(uiFig);
figProps.Controller;
controllerProps = struct(controller);
container = controllerProps.Container;
win = container.CEF
win.maximize();
end
I then profiled different apps with three different approaches:
  1. Tic Toc
  2. Elapsed clock time
  3. profile on; APP(); profile off; profile viewer
For some reason, each of these measuring approachess have shown varying runtime durations for the line containing the "pause" statement. None of them were actually close to the defined "0.1" seconds. Instead they ranged from 1 seconds to about 8 seconds. The maximizing took place in each of the apps' StartUp-Functions. After moving the code to a Button's callback instead, the required time to execute the maximization reduced to a negligible level.
I therefore have the feeling that pausing during startup gives another thread priority and thus takes longer than it should.
Additionally I found out, that the code still works after replacing "pause" with a "drawnow" statement. But the weird runtime behavior stays the same.
My question is:
Are there any other ways of accessing the controller instead of using pause/drawnow? Is there a better "hack" to achieve the same "borderless" programmatic window maximization? Is there any way to implement some kind of post-Startup Callback?
Thanks in advance!

Answers (3)

Image Analyst
Image Analyst on 28 Sep 2017
Attached is Yair Altman's Java way to maximize a figure window.

Jan
Jan on 28 Sep 2017
Edited: Jan on 28 Sep 2017
pause and drawnow trigger an update of all components drawn to the screen. Therefore it is expected, that pause uses more time than the specified delay.
There is no way to display a figure correctly without giving Matlab the time to update all components and evaluate all events. I do not know which parts take 8 seconds on your computer, but this is slow.
Under Windows you can use this Mex function also: FEX: WindowAPI. But this cannot avoid the need to let the drawnow or pause perfrom the screen updates.
Is this really the complete code?
figProps.Controller; % Do you mean: controller = figProps.Controller ?
controllerProps = struct(controller);

Yair Altman
Yair Altman on 29 Sep 2017
Use the drawnow function instead of pause - drawnow returns only after the entire GUI is processed and displayed (which can take quite a while with the web-based GUI that you are using).
Note that the solutions proposed by Image Analyst and Jan Simon will not work for you, because they only work on the Java-based figures (the old/existing non-web-based GUI framework) - not the new web-based GUI that you are apparently using.

Categories

Find more on Migrate GUIDE Apps 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!