Can a UI Figure be centered before displaying?

조회 수: 14 (최근 30일)
Daelyn Greene
Daelyn Greene 2019년 1월 17일
댓글: Cédric Cannard 2023년 3월 3일
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?

채택된 답변

Image Analyst
Image Analyst 2019년 1월 17일
편집: Image Analyst 2019년 1월 17일
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.
  댓글 수: 1
Cédric Cannard
Cédric Cannard 2023년 3월 3일
Thanks! Even simpler:
h.Visible = 'off'; % hide it immediately
movegui(h,'center') % center
h.Visible = 'on'; % show it

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by