Updating Handles in WindowKeyPressFcn

조회 수: 4 (최근 30일)
Matt
Matt 2013년 1월 2일
댓글: PIEASIAN ISB 2019년 8월 27일
I'm trying to make a panel visible when the user presses the 'a' key. However the handles structure is not updating like I want it to.
function figure1_WindowKeyPressFcn(hObject , eventdata , handles)
switch eventdata.Key
case 'a'
set(handles.mypanel,'visible','on');
end
guidata(hObject,handles);
Any ideas why this is not causing the panel to become visible? Or a workaround?
Thanks, Matt
  댓글 수: 1
PIEASIAN ISB
PIEASIAN ISB 2019년 8월 27일
Hi, i am calling a callback function by using uimenu. Function name movx. In movx i define a windowkeypressfunc key1. I press desired key and perform the task upto this its ok. But how disable this windowkeypressfunc. I want disable this windowkeypressfunc and when i call it back it should be enabled. Kindly any suggestions help Thanks

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

답변 (3개)

Walter Roberson
Walter Roberson 2013년 1월 2일
편집: Walter Roberson 2013년 1월 2일
Try adding a
drawnow()
after the set()
Do you want the panel to become visible on "a" or on "m" ? You coded "m"
Note: you do not need to guidata() in the case you show.
  댓글 수: 2
Matt
Matt 2013년 1월 2일
Sorry, it should be an 'a'. drawnow() did not work either. I use several set and get statements in callbacks and custom functions throughout the script. It is only in the WindowKeyPressFcn in which this became a problem. Any other suggestions? Thanks for your time.
Walter Roberson
Walter Roberson 2013년 1월 2일
Can you confirm that the function is being activated? Such as by putting
disp(eventdata)
just under the function header?

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


Sean de Wolski
Sean de Wolski 2013년 1월 2일
  • Stick a break point on the set() line. What does:
ishandle(handles.mypanel)
return?
  • Are you sure the panel exists and that its stacking order is above another panel that it might be hiding behind?
doc uistack %for more info

Jan
Jan 2013년 1월 2일
I do not see the connection between the code and updating the handles struct. The handles struct is not modified at all in the code, therefore the guidata(hObject, handles) command is useless here. But there might be another problem, see FAQ: Incomplete handles struct in callbacks:
function figure1_WindowKeyPressFcn(hObject , eventdata , handles)
...
guidata(hObject,handles);
The handles struct from the input arguments is not the current version. If this causes your problems, use this:
function figure1_WindowKeyPressFcn(hObject , eventdata , handles)
handles = guidata(hObject); % Current version!
handles.myData = rand(5); % Any changes
guidata(hObject, handles); % Store updated struct

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by