【发布时间】:2011-07-12 20:14:40
【问题描述】:
我已经拥有在 MATLAB 中拖放单个框所需的功能。我编写的代码用几个框填充了该图。在另一个循环中,我在图中填充了更多的框(以字符串形式保存不同的信息)。
这两组框由我在它们的 UserData 中放置的数字相关(对应的数字;对于每个框,都有另一个具有相同 UserData 内容的框)。通过查找包含相同 UserData 的框(并因此关联它们),我希望能够通过右键单击将第一组框的成员重新定位到相对于第二组框的相应成员的相同位置我刚刚拖动的框(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.
【问题讨论】:
-
是的,它应该像您描述的那样工作。那么问题是什么?
-
当我右键单击一个框时,我正在使用它的手柄。一旦我移动了第二组盒子的一个成员,我就使用函数 findobj(.) ,它应该返回另一个盒子的句柄(我想要相对于我提到的第一个盒子重新定位的盒子)。由于使用了两个句柄,并且代码什么也不做 - 也没有返回任何错误消息,因此似乎存在某种冲突。我将编辑问题以包含一些我希望用于重定位的代码。
标签: matlab drag-and-drop figure