Stop callback function in pushbutton if previous pushbuttons not pushed, GUI
1 回表示 (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
Walter Roberson
2013 年 9 月 16 日
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 件のコメント
Walter Roberson
2013 年 9 月 16 日
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')
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!