Updating handles from within Position Changed Callback
조회 수: 1 (최근 30일)
이전 댓글 표시
I have defined an impoint roi object inside of an axis. I've set up the impoint with a callback for position changed function, and in that function I change the position of a second impoint as follows:
function positionChanged(pos)
handles = guihandles;
pointMoved = gco; %moving point is currently selected object
...
kids = get(pointMoved,'Children');
kids2 = get(correspondingPoint,'Children');
set(kids2(1),'Position',get(kids(1),'Position'));
set(kids2(1),'String',get(kids(1),'String'));
set(kids2(2),'XData',get(kids(2),'XData'));
set(kids2(2),'YData',get(kids(2),'YData'));
set(kids2(3),'XData',get(kids(3),'XData'));
set(kids2(3),'YData',get(kids(3),'YData'));
I'm just trying to get correspondingPoint to have the same values and positions as the point generating the callback, and the above works pretty well for this. The problem is that upon moving or resizing my figure window, all of those set values (minus the 'String' property, for some reason) revert, and my second impoint goes back to the position it had before the callback.
댓글 수: 2
Sean de Wolski
2014년 7월 15일
My guess is that it's the gco. Can you get the handle from somewhere else?
채택된 답변
Alfonso Nieto-Castanon
2014년 7월 15일
Your figure might have a resizefcn callback that could be reverting those values. Check:
get(gcf,'resizefcn');
댓글 수: 7
Alfonso Nieto-Castanon
2014년 7월 17일
편집: Alfonso Nieto-Castanon
2014년 7월 17일
I would do something like this:
f = impoint(gca,handles.lastPoint{1},handles.lastPoint{2});
setColor(f,color);
pos = getPosition(f);
setString(f,[num2str(pos(1)) ', ' num2str(pos(2))]);
%duplicate on the filtered axis
f2 = impoint(handles.axFiltered,handles.lastPoint{1},handles.lastPoint{2});
setColor(f2,color);
pos2 = getPosition(f2);
setString(f2,[num2str(pos2(1)) ', ' num2str(pos(2))]);
%ensure string gets updated if user interactively moves point
addNewPositionCallback(f,@(varargin)positionChanged(f,f2));
addNewPositionCallback(f2,@(varargin)positionChanged(f2,f));
The last two lines are the ones being modified. I am using that syntax to pass the impoint objects to the positionChanged function. Then you could have the function positionChanged something like:
function positionChanged(f1,f2)
pos=getPosition(f1);
setPosition(f2,pos);
end
And that will keep both impoint object positions "locked". Also note that if you have many impoint objects that want similarly locked (in pairs), you can just have one single positionChanged function that serves all of these, and define during the addNewPositionCallback call the appropriate parameters to pass to this function for each pair of impoint objects. Does this make sense?
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!