How to write correct signature for callback function which includes handles structure?
10 views (last 30 days)
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)
While my function display_frame was defined as:
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);
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.
Adam on 12 Dec 2016
@(src,evt) display_frame( src,evt,handles.edit3 )
should work as the call.
as the function signature, and
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 );