Set uicontrol position relative to a subplot
조회 수: 21 (최근 30일)
이전 댓글 표시
Is it possible to set the position of a GUI control element (e.g. a slider) relative to a subplot's position rather than relative to the whole figure?
The code I'm trying to write can have a variable number of subplots and it would easiest if I could set the uicontrol 'Position' relative to the subplot. For example, I might have two or three subplots and I want a slider under each of them.
Thanks!
댓글 수: 0
채택된 답변
Walter Roberson
2015년 5월 6일
No.
However, you can create a uipanel and the panel can contain axes and uicontrol such as sliders. uicontrol() 'Position' properties are relative to the container, not to the figure. axes cannot contain uicontrol, but uipanel can.
For example:
fignum = figure('Units', 'normal', 'Position', [0.1 0.1 .8 .8]); %not quite full screen
subgroup1 = uipanel('Parent', fignum, 'Units', 'normal', 'Position', [0 2/3 1 1/3]) %top third
subgroup1_plotbox = uipanel('Parent', subgroup1, 'Units', 'normal', 'Position', [0 .1 1 .9]) %plot in top 9/10 of the group
subgroup1_controls = uipanel('Parent', subgroup1, 'Units', 'normal', 'Position', [0 0 1 .1]); %control area in bottom 1/10 of the group
subgroup1_axes = axes('Parent', subgroup1_plotbox);
plot(1:50, rand(1,50), 'Parent', subgroup1_axes); %throw up some content
subgroup1_slider = uicontrol('style', 'slider', 'Parent', sugroup1_controls, ..... );
You do not actually need to create the two sub-panels for the above purpose, as you could put both the axes and the slider into 'Parent', subgroup1, making appropriate adjustments to the Position properties for those. The above example is for illustrative purposes, showing how you can create groups of objects in positional relationship to other groups of objects. You could resize the plot area and group of controls by adjusting the Position of the appropriate uipanel relative to the containing object. For simpler cases, that isn't worth the effort.
Each uipanel can act much like a figure (with some differences like not having individual toolbars), including uipanel being able to contain other uipanel.
댓글 수: 0
추가 답변 (2개)
Joseph Cheng
2015년 5월 6일
well your explanation of the problem is exactly how you'd do it. you would first get the position of the subplot then perform the offset.
this isn't pretty but for a 2 min example it'll show you what you can accomplish
clf;
for ind =1:3
hsub(ind) =subplot(3,1,ind),plot(randi(10,1,10));
subpos = get(hsub(ind),'position');
hslide(ind) = uicontrol('style','slider')
set(hslide(ind),'units',get(hsub(ind),'units'))
slideoff = [-.05 -.05 0];
slidepos = get(hslide(ind),'position')
slidepos = [subpos(1:3)+slideoff slidepos(end)]
set(hslide(ind),'position',slidepos);
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!