How to write correct signature for callback function which includes handles structure?

2 views (last 30 days)
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!

Accepted Answer

Adam
Adam on 12 Dec 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 );

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!