在图中移动多个框? [英] Moving multiple boxes in figure?

查看:121
本文介绍了在图中移动多个框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经拥有MATLAB中图形拖放单个框所需的功能。我写的代码填满了几个框。在另一个循环中,我填充了更多的框(其中包含字符串形式的不同信息)。

I already have the functions required to drag and drop a single box in a figure in MATLAB. The code I wrote fills the figure with several boxes. With another loop I filled the figure with more boxes (which hold different information in string form).

这两组框与我们放在用户数据中的数字相关(相应的数字;每个框中有另一个具有相同的UserData内容)。通过查找包含相同UserData(并因此关联它们)的框,我希望能够将第一组框的一个成员相对于第二组框的相应成员重新定位到相同的位置,方法是右键单击我刚拖动的框(uicontextmenu)。

These two sets of boxes are related by the numbers I placed in their UserData (corresponding numbers; for each box, there's another with the same UserData content). By finding boxes containing the same UserData (and thus relating them) I want to be able to relocate a member of the first set of boxes to the same position relative to the corresponding member of the second set of boxes, by means of right clicking on the box I just dragged (uicontextmenu).

function recallfcn(hObject,eventdata)
for ydx=1:2
    diag_detail=get(gco,'UserData');   % This line should be in the drag fcn
    diag_pos=get(gco,'Position');      % So should this one (for current objects)
    xvar=diag_pos(1,1);
    yvar=diag_pos(1,2);
    detail=[diag_detail ydx]; 
    set(findobj('UserData',detail),'Position',[xvar+(ydx-1.5) yvar+0.5 0.8 0.8]);
end
end

% ydx is only there to add another level of detail as I'm actually looking to move     
% two boxes of the 'first kind', each of which have 2 numbers in user data, the first  
% number being the same, and the second number distinguishing the first box from the 
% second. The premise is the same.


推荐答案

我通常使用 findall 而不是 findobj ,以防对象的句柄从外部看不到。除此之外,我不明白为什么你的代码不起作用。

I usually use findall instead of findobj, in case the handles of the objects are not visible from the outside. Other than that I don't see why your code wouldn't work.

这里有一个例子:

%# make a figure with two buttons, same userData
fh=figure,
uicontrol('userdata',[2 3],'parent',fh)
uicontrol('userData',[2 3],'units','normalized','position',[0.5 0.5,0.1 0.1],'parent',fh)

%# change color to red
set(findall(fh,'userData',[2 3]),'backgroundcolor','r')

%# move to the same position
set(findall(fh,'userData',[2 3]),'position',[0.3,0.3,0.1,0.1])

这篇关于在图中移动多个框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆