Question

Initially my prog is like that (playing sound and judge what kind of sound is) :

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

Now I'm trying to make it more interactive with GUI, I'm using GUIDE and i've generate a .fig which contain 4 buttons: OK button, BIRD, WATER, WIND

I've also my callbacks which are empty now What I want to do is:

-Initially all buttons are inactive -Participant should press on ok to begin -play sounds -activate the buttons (sound bird, water, wind) -catch response -deactivate button -wait for press ok for new trial

How could I adapt my initial code the the callback, where should I put my loop ? Thanks

Was it helpful?

Solution

Add these at the start of guiname__OpeningFcn -

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

Edit your button callbacks to these -

% --- 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;

Note: At any point of time view handles.asw to look at the button clicks history.

Suggestion: If it's okay to show the choices made by the GUI user as a list, you might consider adding a Table into the GUI. You can put the data from handles.asw into such a Table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top