MATLAB Answers

0

Can a UI Figure be centered before displaying?

Asked by Daelyn Greene on 17 Jan 2019
Latest activity Edited by Image Analyst
on 17 Jan 2019
I am using movegui(_______,'center') to center my UI figure. While this works, I'd prefer to not have the UI showing at all until the figure is centered. Is this possible?

  0 Comments

Sign in to comment.

1 Answer

Answer by Image Analyst
on 17 Jan 2019
Edited by Image Analyst
on 17 Jan 2019
 Accepted Answer

Try this:
h = figure; % Create a figure.
h.Visible = 'off'; % Hide it immediately.
h.Units = 'normalized';
% Get original width and height.
originalSize = h.Position
width = originalSize(3)
height = originalSize(4)
% Reassign the size (optional - only if you want to);
width = .5;
height = 0.3; % Whatever you want.
% Get the left and bottom coordinates so we can reposition to there.
xLeft = 0.5 - width/2;
yBottom = 0.5 - height/2;
% Reposition the figure. Here is where it actually gets moved and (optionally) resized.
h.Position = [xLeft, yBottom, width, height]
h.Visible = 'on'; % Now show it.

  0 Comments

Sign in to comment.