connect two uicontrol object with a line
4 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm trying to get a nice and tidy GUI with a veriable number of uicontrol objects. To get a clean and clear layout I want to connect several objects with a simple line or path. Has anybody an idea how to implement this?
Thanks for your response, CN
0 件のコメント
採用された回答
Sean de Wolski
2012 年 6 月 5 日
You could use an invisible axes in the background and draw line objects. For example:
fig = figure('units','pix');
pos = get(fig,'position');
ax = axes('units','pix','outerposition',[0 0 pos([3 4])],...
'position',[0 0 pos([3 4])],'parent',fig,'visible','off','xlim',...
[0 pos(3)],'ylim',[0 pos(4)]);
h(3) = uicontrol('units','pix','position',[300 10 100 100],'style','push');
h(2) = uicontrol('units','pix','position',[10 10 100 100],'style','push');
h(1) = uicontrol('units','pix','position',[300 300 100 100],'style','push');
pos = get(h,'position');
for ii = 1:length(h)-1
line('xdata',[pos{ii}(1)+pos{ii}(3)/2, pos{ii+1}(1)+pos{ii}(3)/2],...
'ydata',[pos{ii}(2)+pos{ii}(4)/2, pos{ii+1}(2)+pos{ii}(4)/2],'parent',ax)
end
7 件のコメント
Sean de Wolski
2012 年 6 月 15 日
There are a few things that are different I believe.
-The uicontrol callbacks will fire if you are zooming or panning, this is not true for a buttondownfcn which is disabled while in one of these interactive modes.
-The buttondownfcn fires when the button goes down, the callbacks fire when it comes up.
There are probably a few other things though I can't think of them right now.
その他の回答 (3 件)
Image Analyst
2012 年 6 月 5 日
Did you try the line() function? I usually use it on axes, but it might work on your main figure also.
2 件のコメント
Walter Roberson
2012 年 6 月 5 日
line() can only be used in axes. The routines that can create graphical items that are not in axes seem to all be named starting with "ui": uicontrol(), uitab(), uitable(), uipanel()
Walter Roberson
2012 年 6 月 5 日
You need to create an axes in order to draw the line.
My recollection is that uicontrol() objects take graphical precedence over axes (that is, if you have a uicontrol() that is positioned in an area where the axes happens to be, the control will show up on top.)
Adam Kaas
2012 年 6 月 5 日
I'm guessing there is a more efficient way, but you could always get a picture of the path you want either online or make it using MSpaint or some other software and insert it as an axes. Are you using GUIDE?
参考
カテゴリ
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!