필터 지우기
필터 지우기

Brush callbacks: what am I missing?

조회 수: 11 (최근 30일)
David Goldsmith
David Goldsmith 2013년 3월 27일
Hi, folks! So, the Tips for the brush command state (I've spliced the following up a little to focus on ActionPostCallback but still include all the pertinent available info): "You can program the following callbacks for brush mode operations. ActionPostCallback < function_handle > — Function to execute after brushing Use this callback to execute code when a brush operation ends. The function handle should reference a function with two implicit arguments: function myfunction(obj,event_obj) % obj handle to the figure that has been clicked % event_obj object containing struct of event data The event data struct has the following field: AxesThe handle of the axes that is being brushed"
OK, so I do the following:
>> f = @(x,y) disp([x y]);
>> f(1,2)
1 2
>> plot(1:10, 1:10)
>> bO = brush(1)
bO =
graphics.brush
>> set(bO, 'ActionPostCallback', f, 'enable', 'on')
>> get(bO)
ButtonDownFilter: @localButtonDownFilter
ActionPreCallback: []
ActionPostCallback: @(x,y)disp([x,y])
Enable: 'on'
FigureHandle: 1
Color: [1 0 0]
Then, when I brush the plot, the figure disappears and back in the command window I get:
"Warning: An error occurred during the mode callback.
> In uitools.uimode.fireActionPostCallback at 14
In datamanager.brushup at 114
In brush>@(es,ed)datamanager.brushup(es,ed)
In hgfeval at 63
In uitools.uimode.modeWindowButtonUpFcn at 46
In uitools.uimode.modeControl>localModeWindowButtonUpFcn at 155"
and no display of either the figure's handle nor the axis' handle.
What am I missing?
Thanks,
OlyDLG

채택된 답변

per isakson
per isakson 2013년 3월 27일
Run this script and try the brush. | 1 2| will be displayed in the command window.
%%Script
plot( 1:10, 1:10 )
bO = brush( gcf );
x = 1;
y = 2;
set( bO, 'ActionPostCallback', @(ohf,s) BrushAction(ohf,s,x,y), 'enable', 'on' )
where
function BrushAction( varargin )
disp([ varargin{3:4} ])
end
I guess this does what you expected. It is much easier to debug ordinary functions.
  댓글 수: 1
David Goldsmith
David Goldsmith 2013년 3월 27일
Thanks, Per, that showed me what I was missing: I thought that "The function handle should reference a function with two implicit arguments" meant that I didn't need to actually include those implicit arguments in the value of the 'ActionPostCallback' property (what I provided was a simplified example of what I'm really trying to do, which is make an object method the callback). Your example--with explicit inclusion of the implied arguments in the property value specification, along w/ the use of varargin in the callback definition--showed me, quite litterally, what I was missing. Thanks!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by