2014-03-30 69 views
1

最初我PROG就是這樣(播放聲音和判斷是什麼樣的聲音):循環在圖形用戶界面的許多試驗

n_repetition=10 
for i=1:n_repetition 

    playsound(strcat(i,'wav')); 

    answer=input(' answer q/z/e ?','s'); 
    switch answer 
     case 'q' 
      asw="bird"; 
     case 'z' 
      asw="water"; 
     case 'e' 
      asw="wind"; 
     otherwise 
      disp('error'); 
    end 
end 

現在我試圖使其與GUI更多的互動,我使用指南和我產生包含4個按鈕一.FIG:OK按鈕,鳥,水,風

,我也有我的回調它們是空的,現在 我想要做的是:

- 最初所有的按鈕都不起作用 - 參與者應該按下按鈕o開頭 - 播放聲音 -activate按鈕(音鳥,水,風) -catch響應 -deactivate按鈕 - 等待了按確定新的審判

我怎麼能適應我最初的代碼中的回調,我應該在哪裏放置我的循環?

handles.song_count = 0; 
handles.asw = cell(10,1); 

編輯您的按鈕回調到這些 - - 感謝

回答

1

在guiname__OpeningFcn開始添加這些

% --- Executes on button press in ok_button. 
function ok_button_Callback(hObject, eventdata, handles) 

handles.song_count = handles.song_count +1; 
filename = strcat(num2str(handles.song_count),'.wav'); 
[y,~] = audioread(filename); 

%%// Use soundsc or your custom playsound function to play the sounds 
soundsc(y); %playsound(strcat(i,'wav')); 

guidata(hObject, handles); %%// Save handles data 

return; 


% --- Executes on button press in bird_button. 
function bird_button_Callback(hObject, eventdata, handles) 

asw = 'bird'; %%// Do something with 'asw' 
handles.asw(handles.song_count) = {asw}; %%// Store the 'asw' values as a cell array 
guidata(hObject, handles); %%// Save the handles data 

return; 


% --- Executes on button press in water_button. 
function water_button_Callback(hObject, eventdata, handles) 

asw = 'water'; %%// Do something with 'asw' 
handles.asw(handles.song_count) = {asw}; %%// Store the 'asw' values as a cell array 
guidata(hObject, handles); %%// Save the handles data 

return; 


% --- Executes on button press in wind_button. 
function wind_button_Callback(hObject, eventdata, handles) 

asw = 'wind'; %%// Do something with 'asw' 
handles.asw(handles.song_count) = {asw}; %%// Store the 'asw' values as a cell array 
guidata(hObject, handles); %%// Save the handles data 

return; 

注:時間視圖handles.asw的任何角度去看待按鈕點擊歷史記錄。

建議:如果可以將GUI用戶所做的選擇顯示爲列表,那麼可以考慮在GUI中添加一個Table。您可以將來自handles.asw的數據放入這樣一個Table

+0

大謝謝它的作品! – ranell