Stop callback function in pushbutton if previous pushbuttons not pushed, GUI

2 views (last 30 days)
Hi, all! I am not good in matlab gui. I have quite simple GUI Listening Test, there are three pushbuttons: first one plays audio files one by one, second and third button saves resulting files. Better explanation: after listening to the audio (first button) subjects need to decide to which category it belongs (category A second button, category B third button). The problem is following: how to stop playing next audio by pushing first button if subject did not pushed 2nd and 3rd buttons?? The ideal scenario is: push 1st button, decide which category (push A or B buttons), then start again from 1st button. There should be error message if subject pushes 1st button without pushing previous 2nd or 3rd buttons. So, how to make this condition?? My code:
% --- Executes on button press in PLAYNEXTAUDIObutton.
function PLAYNEXTAUDIObutton_Callback(hObject, eventdata, handles)
% hObject handle to PLAYNEXTAUDIObutton(see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global times_pushed fileCounter
if fileCounter < handles.m % total number of audio files
handles.FiletoPlay = handles.fileList{handles.perm(fileCounter)};
[y, Fs]=wavread(handles.FiletoPlay);
handles.audio = audioplayer(y,Fs);
play(handles.audio);
end
if fileCounter == handles.m
stop(handles.audio);
msgbox('Test is finished. Thank you for your participation!');
[~,order] = sort(handles.perm);
handles.result = handles.answer(order);
handles.result = handles.result';
finalresults = horzcat(handles.fileList, handles.result);
xlswrite([char(handles.name) char(handles.age) '_results.xlsx'], finalresults);
end
fileCounter = fileCounter + 1;
times_pushed = 0;
guidata(hObject,handles);
% --- Executes on button press in Abutton.
function Abutton_Callback(hObject, eventdata, handles)
% hObject handle to FRONTbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fileCounter
handles.answer{fileCounter} = 'categoryA';
guidata(hObject,handles);
% --- Executes on button press in Bbutton.
function Bbutton_Callback(hObject, eventdata, handles)
% hObject handle to BACKbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fileCounter
handles.answer{fileCounter} = 'categoryB';
guidata(hObject,handles);
Thank you in advance!

Accepted Answer

Walter Roberson
Walter Roberson on 16 Sep 2013
When a button should not be pushable, set() 'enable', 'off' for it. At the time the state changes so that it becomes meaningful to push it, set() 'enable', 'on' for it.
  3 Comments
Walter Roberson
Walter Roberson on 16 Sep 2013
set(handles.Bbutton, 'enable', 'off')
Do that after the button is created but before control is turned over to the user.
Inside the Abutton callback, when it is time to allow B to be pushed,
set(handles.Bbutton, 'enable', 'on')

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!