1

MATLAB の Figure に 1 つのボックスをドラッグ アンド ドロップするために必要な関数は既にあります。私が書いたコードは、図をいくつかのボックスで埋めます。別のループで、Figure をさらにボックス (文字列形式でさまざまな情報を保持) で埋めました。

これら 2 つのボックスのセットは、UserData に配置した番号によって関連付けられています (対応する番号。ボックスごとに、同じ UserData コンテンツを持つ別のボックスがあります)。同じ UserData を含む (したがって、それらを関連付ける) ボックスを見つけることで、最初のボックス セットのメンバーを、2 番目のボックス セットの対応するメンバーに対して同じ位置に再配置できるようにしたいと考えています。ドラッグしたばかりのボックス (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.
4

3 に答える 3

3

オブジェクトのハンドルが外側から見えない場合に備えて、私は通常、findallの代わりに使用します。findobjそれ以外は、コードが機能しない理由がわかりません。

次に例を示します。

%# 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])
于 2011-07-13T14:54:51.630 に答える
3

Jonas が言及しているように、オブジェクトの'HandleVisibility'プロパティは、オブジェクトが親の子のリストに表示されるかどうか、したがってFINDOBJなどの関数によって返されるかどうかを決定します。標準的な修正方法は、代わりに関数FINDALLを使用することです。

ただし、'HandleVisibility'プロパティは、オブジェクトが現在のオブジェクトになることができるかどうか(つまり、関数 GCO によって返されるかどうか) を決定する際にも使用されます。に設定されている場合'off'、そのオブジェクトは現在のオブジェクトにはなりません。さらに、オブジェクトの親 Figureの'HandleVisibility'プロパティが に設定されている場合、その子 (オブジェクトを含む) は現在のオブジェクトになることはできません。'off'

'HandleVisibility'がすべてのオブジェクトとフィギュアに設定されている'on'場合、すべてが正常'callback'に機能すると思います。

于 2011-07-13T15:19:47.220 に答える
0

x と y ベクトルの順序を逆にする必要があり、ループを 1 つだけ使用できます。コードの変更点は次のとおりです。

x2=x(end:-1:1); % invers the ordre
y2=y(end:-1:1);

for i=1:length(x)

set(hLine,'xdata',x(i),'ydata',y(i)); % move the point using set
                                  % to change the cooridinates.

set(hLine2,'xdata',x2(i),'ydata',y2(i));

 M(i)=getframe(gcf);

end
于 2016-05-10T13:56:39.100 に答える