Resizing my figure table

5 次查看(过去 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