Matlab 2016b - Maximizing affects pause
12 次查看(过去 30 天)
显示 更早的评论
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:
- Tic Toc
- Elapsed clock time
- 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!
0 个评论
回答(3 个)
Jan
2017-9-28
编辑:Jan
2017-9-28
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);
0 个评论
Yair Altman
2017-9-29
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!