필터 지우기
필터 지우기

Keyboard interaction using GUI and callback error

조회 수: 2 (최근 30일)
Emanuele Gandola
Emanuele Gandola 2015년 11월 23일
댓글: Walter Roberson 2015년 11월 24일
Hallo! I've a GUI that upload images, make operation on that and than I show the result on a separate figure. Once the figure is showed I want to select some highlited objects using push buttons. This is the code of a button.
function specie1_Callback(hObject, eventdata, handles)
global stats L B path data count resolution Nimg;
figure(1);
[data count c] = riconosci(stats,L,B,resolution,1,data,count,Nimg);
set (handles.sp1number, 'String', c );
set (handles.total, 'String', num2str(size(data,1)-1));
When i use these buttons all works great but to perform the selection faster I'd like to select buttons with keyboard input and I try this code
function figure1_WindowKeyPressFcn(hObject, eventdata, handles)
switch eventdata.Key
case '1'
specie1_Callback
case '2'
specie2_Callback
case '3'
specie3_Callback
end
But when I push the kay 1 for example( that activate the callback of button specie1) and than make the selection I have this error.
??? Input argument "handles" is undefined.
Error in ==> interfaccia>specie1_Callback at 185
set (handles.sp1number, 'String', c );
Error in ==> interfaccia>figure1_WindowKeyPressFcn at 442 specie1_Callback
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> interfaccia at 16
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)interfaccia('figure1_WindowKeyPressFcn',hObject,even tdata,guidata(hObject))
??? Error while evaluating figure WindowKeyPressFcn
??? Error using ==> feval
Undefined function or method 'specie1_KeyPressFcn' for input arguments of type
'struct'.
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> interfaccia at 16
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)interfaccia('specie1_KeyPressFcn',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol KeyPressFcn
I don't understand where is the error. Thanks a lot in advance.

채택된 답변

Ingrid
Ingrid 2015년 11월 23일
have you tried this:
function figure1_WindowKeyPressFcn(hObject, eventdata, handles)
switch eventdata.Key
case '1'
specie1_Callback(hObject, eventdata, handles)
case '2'
specie2_Callback(hObject, eventdata, handles)
case '3'
specie3_Callback(hObject, eventdata, handles)
end
it seems that you are not calling the function with the proper amount of inputs.
  댓글 수: 3
Ingrid
Ingrid 2015년 11월 24일
I think I do not understand your question completely, but I think it is a better approach to write separate functions that are not pushbutton functions and that you call these functions with the keyPresFcn. Also the use of globals is not necessary normally.
Walter Roberson
Walter Roberson 2015년 11월 24일
I think you deleted your earlier question in which I had asked you to explain whether your GUI was different than your figure(1). Or perhaps it was closed and I cannot see it now. Either way, please show
fig1 = figure(1);
get(fig1, 'WindowKeyPressFcn')
Is it the same as
@(hObject,eventdata)interfaccia('specie1_KeyPressFcn',hObject,eventdata,guidata(hObject))
?
What is the figure number associated with your GUI? Are you specifically opening figure(1) as a new figure? GUIDE does not normally manage multiple figures.

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

추가 답변 (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