Hello. I'm fairly new to using GUIDE so thank you for your patience. I have gui with "Record On/Off" pushbutton which serves to start and stop a timer object. The default setting is therefore infinite in that the timer object will run until the stop button is pressed. Additionally, when pushbutton is pressed to stop the timer, several other processes are performed (e.g., changing the color of the button, preprocessing and saving the data generated during the timer object etc.).
However, I have an optional setting in which the user can specify a custom duration. When a duration is specified, the 'TasksToExecute' is set thus stopping the timer automatically after the duration has elapsed.
The issue is, that because the Recording pushbutton executes several operations in addition to stopping the timer, I need to trigger the button press via the timer's StopFcn. Being a novice with guide, I'm confused about executing callbacks within another call back. I've pasted the relevant sections of code below:
function Record_Callback(hObject, eventdata, handles)% hObject handle to Record (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
RecordStatus = get(hObject,'Value');runstr=get(hObject,'string');if RecordStatus == 1 cla; %clears current axes if applicable
set(hObject, 'string', 'STOP Recording'); %updates text of record button
set(hObject, 'ForegroundColor', 'black'); %updates color of record button
Duration_MS = handles.dur * (60 * handles.hertz); %Pre-allocates duration of recording based on sample rate and time
if Duration_MS > 0; NumExecutions = [handles.dur * 60] / get(handles.tmr, 'Period'); set(handles.tmr, 'TasksToExecute', NumExecutions); end% does some other cool stuff irrelevant here
start(handles.tmr); %starts the timer function
guidata(hObject, handles);elseif RecordStatus == 0 stop(handles.tmr); %stops the timer (and stops recording)
timeElapsed = toc; % does some other cool stuff after the timer is stopped.
Here is the StopFcn which I'd like to figure out how to simulate a button press (i.e. stop recording).
function StopRNG_callback(obj,event,hObject)handles=guidata(hObject);disp(['recording should have stopped at ' toc]); %shows when recording ended.
% So here is where I need to call the Record pushbutton callback. But I don't understand how to execute a callback within another callback.
guidata(hObject, handles);
Best Answer