필터 지우기
필터 지우기

Resizing my figure table

조회 수: 2 (최근 30일)
Tan
Tan 2021년 8월 27일
답변: Chunru 2021년 8월 27일
Hi, I would like to ask how can I make my "PUSH" Buttons change their position when I enlarge my figure.
Currently my "PUSH" Buttons have the positions specified, and when i maximise the figure, my subplotted axes will change in position but the push buttons remain the same.
Thank you!
function []=plotting_8_figures()
S.fh = figure('units','pixels',...
'position',[350 100 1200 1000],...
'menubar','none',...
'numbertitle','off',...
'name','8 Figures axes',...
'resize','on');
for n=1:8
subplot(4,2,n)
end
S.pb(1) = uicontrol('style','push',...
'units','pixels',...
'position',[450 820 120 30],...
'fontsize',10,...
'string',['PUSH']);
S.pb(2) = uicontrol('style','push',...
'units','pixels',...
'position',[1000 820 120 30],...
'fontsize',10,...
'string',['PUSH']);
S.pb(3) = uicontrol('style','push',...
'units','pixels',...
'position',[450 600 120 30],...
'fontsize',10,...
'string',['PUSH']);
S.pb(4) = uicontrol('style','push',...
'units','pixels',...
'position',[1000 600 120 30],...
'fontsize',10,...
'string',['PUSH']);
S.pb(5) = uicontrol('style','push',...
'units','pixels',...
'position',[450 380 120 30],...
'fontsize',10,...
'string',['PUSH']);
S.pb(6) = uicontrol('style','push',...
'units','pixels',...
'position',[1000 380 120 30],...
'fontsize',10,...
'string',['PUSH']);
S.pb(7) = uicontrol('style','push',...
'units','pixels',...
'position',[450 160 120 30],...
'fontsize',10,...
'string',['PUSH']);
S.pb(8) = uicontrol('style','push',...
'units','pixels',...
'position',[1000 160 120 30],...
'fontsize',10,...
'string',['PUSH']);
set(S.pb(:),{'callback'},{{@pb1_call,S};{@pb2_call,S};{@pb3_call,S};{@pb4_call,S}...
;{@pb5_call,S};{@pb6_call,S};{@pb7_call,S};{@pb8_call,S}});
function [] = pb1_call(varargin)
close(S.fh)
end
function [] = pb2_call(varargin)
close(S.fh)
end
function [] = pb3_call(varargin)
close(S.fh)
end
function [] = pb4_call(varargin)
close(S.fh)
end
function [] = pb5_call(varargin)
close(S.fh)
end
function [] = pb6_call(varargin)
close(S.fh)
end
function [] = pb7_call(varargin)
close(S.fh)
end
function [] = pb8_call(varargin)
close(S.fh)
end
end

채택된 답변

Chunru
Chunru 2021년 8월 27일
A simple approach is to use normalized units for specifying position:
S.pb(1) = uicontrol('style','push',...
'units','normalized',...
'position',[0.2 0.4 0.2 0.1],... % adjust these values
'fontsize',10,...
'string',['PUSH']);
A more complicated approach is to use the callback function SizeChangedFcn.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by