Keyboard interaction using GUI and callback error

2 vues (au cours des 30 derniers jours)
Emanuele Gandola
Emanuele Gandola le 23 Nov 2015
Commenté : Walter Roberson le 24 Nov 2015
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.

Réponse acceptée

Ingrid
Ingrid le 23 Nov 2015
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 commentaires
Ingrid
Ingrid le 24 Nov 2015
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 le 24 Nov 2015
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by