How to write correct signature for callback function which includes handles structure?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi there!
I'm getting a 'Not enough input arguments' error, when I run my GUI application. At the moment, my GUI has a button called startAcquisition:
function startAcquisition_Callback(hObject, eventdata, handles)
set(handles.video,'FramesAcquiredFcn',@display_frame);
%other stuff
end
While my function display_frame was defined as:
function display_frame(obj,event,handles)
imageData = getdata(obj,1);
%Several image processing operations are made to imageData
%One of those operations calculates the area of a ROI
%The calculated are is stored in variable areaf
area = bwarea(imageData);
areaf = num2str(area);
set(handles.edit3,'String',areaf);
end
What I want to do, is to update a text edit field with the information obtained from the calculated area of every frame.
For what I have found, it seems that there is a problem in the signature of my functions. So, any help will be appreciated.
Thanks!
0 comentarios
Respuesta aceptada
Adam
el 12 de Dic. de 2016
@(src,evt) display_frame( src,evt,handles.edit3 )
should work as the call.
function display_frame(obj,event,hEditbox)
as the function signature, and
set(hEditbox,'String',areaf);
within the function.
You have to actually pass in the arguments, by creating an anonymous function (there is an alternative syntax with cell arrays, but I never use that so wouldn't necessarily get it right).
Never pass the handles structure to a callback though. In your case you only need one editbox from it so I just passed its handle instead (in this case passing handles would not do any harm, but in general it can cause you a lot of headaches as you will get the version of handles from the time you created the callback, not the latest version of it, if you have added your own data to it).
If you do need handles within the callback then pass the handle to the main figure and within the callback use
handles = guidata( hGUI );
where hGUI is the figure handle you passed in. And at the end, if you have added anything to handles within the callback use
guidata( hGUI, handles );
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Object Programming en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!