Set uicontrol position relative to a subplot
Afficher commentaires plus anciens
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!
Réponse acceptée
Plus de réponses (2)
Joseph Cheng
le 6 Mai 2015
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
Mary
le 7 Mai 2015
0 votes
Catégories
En savoir plus sur Subplots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!