필터 지우기
필터 지우기

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

조회 수: 2 (최근 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!

채택된 답변

Walter Roberson
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
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')
Lucky
Lucky 2013년 9월 17일
thank you very much! everything works!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Clocks and Timers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by