MATLAB: Keyboard interaction using GUI and callback error

guiimage processinginteractionkeyboardMATLAB

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.

Best Answer

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.