I'm working on a project where I use a Matlab GUI to switch between audio outputs real-time on button press. I have a Matlab GUIDE file and a function using the Audio System Toolbox that listens to GUI-actions.
The GUIDE file has an OpeningFcn where I declare various handles before the GUI becomes visible. In the OpeningFcn I declare “handles.AttenuationFactor”. It is the idea that when the user later presses the buttons in the GUI the handles.AttenuationFactor changes accordingly.
I have no problem making the separate function listen to GUI-actions. I simply retrieve the GUI handles from the right GUI object:
gui = findobj('Tag','GUI’);
if ~isempty(gui)
% get handles
gdata = guidata(gui);
AttenuationFactor = gdata.AttenuationFactor;
end
%% Perform calculations with attenuation factor
Here’s the pickle: When do I call the function that listens to the GUI?
I cannot call it in the OpeningFcn because the last line of code guidata(hObject, handles) hasn’t been called yet and when retrieving the information from ‘GUI’ ‘handles.attenuationFactor’ therefore does not exist!
I have tried putting the function call in the callback function of the buttonpress, but that would mean creating code that should only be executed once to be evaluated upon every buttonpress.
Is there some way to force the handles to be updated before the function call?