필터 지우기
필터 지우기

How can I disable the call of a function?

조회 수: 8 (최근 30일)
Óscar
Óscar 2014년 11월 11일
댓글: Óscar 2014년 11월 18일
I have defined this function in the OpeningFcn:
set(areas(i),'ButtonDownFcn',@ImageClickCallback);
So it's time the user click in one of those areas Matlab automatically call the function, but now I just want to execute the function sometimes, so How can I disable the listener? (I would like to disable the listener instead of writing inside something like
if control==0
....
else
....
end
)
thank you!

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 11월 12일
Óscar - if you want to disable the callback then you should just "remove" it, and then "add" it back when it is required. Given the name of your call back, it seems that areas(i) could be a handle to a graphics object (image). This handle, and all that which is in areas could be saved to the handles structure in the OpeningFcn as
handles.areas = areas;
guidata(hObject,handles);
Then in whatever callback that fires to decide that the ImageClickCallback should be removed from areas(i), you would do something like
% disable the callback
set(handles.areas(i), 'ButtonDownFcn',[]);
To re-enable this callback, you would then just do the following (in whichever callback that fires to decide that ImageClickCallback is needed)
% enable the callback
set(handles.areas(i), 'ButtonDownFcn', @ImageClickCallback);
  댓글 수: 3
Geoff Hayes
Geoff Hayes 2014년 11월 18일
Óscar - you could probably do the same for a button callback, but why not just disable the button itself so that the user can't press it? To disable the button do
set(handles.pushbutton1,'Enable','off');
and to re-enable the button do
set(handles.pushbutton1,'Enable','on');
Óscar
Óscar 2014년 11월 18일
Hey Geoff, because I sometimes call the buttons using its handle. So I would like to disable that handle momentarily, and if one of my functions calls it, then nothing has to happen(no error either).
Thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by