MatLab returns false figure size in script

4 次查看(过去 30 天)
Hello,
I'm using the following script. If I run each line individually, it gives the right Position so I can get the Width and Height of the figure. But when I use it in a script it keeps giving me the position from before maximizing it.
When asking for the Position after running the script, it gives the right Position too.
is there any way I can resolve that problem?
%% Creating GUI
GUI=uifigure('Name','Spectrograms',...
'NumberTitle','off',...
'WindowState','maximized');
% get window size
Position=get(GUI, 'Position');
GUI_Width=Position(3);
GUI_Height=Position(4);
  1 个评论
Walter Roberson
Walter Roberson 2020-7-21
The uifigure does not exist before you create it so I am not sure what value from "before" you maximized it that you are referring to?

请先登录,再进行评论。

采纳的回答

Arthur Roué
Arthur Roué 2020-7-21
Add a call to drawnow after creating the figure
%% Creating GUI
GUI=uifigure('Name','Spectrograms',...
'NumberTitle','off',...
'WindowState','maximized');
% Update figures and process callbacks
drawnow;
% get window size
Position=get(GUI, 'Position');
GUI_Width=Position(3);
GUI_Height=Position(4);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by