From: Rachel on
Background: I work in a lab that uses the playrec MEX file to access the soundcard via an ASIO driver. This lab uses playrec to present stimuli (audio signals) and record responses (audio signals) from human ears. We've written a function that calls playrec within a loop ("stimulus loop") that is incremented until the number of desired averages is obtained. We have a plot that is updated as each average is obtained, so within the stimulus loop, there are several subfunctions being called.
Specific question: We want to have the ability to pause within the stimulus loop IF NECESSARY (i.e. subjects need a break--we will be testing children who are less predictable than adults). We DON'T want to the function to ask us for an input after each repetition--we want the loop to continue UNLESS we give it an input.
We're having difficulty figuring out how to do this, and any suggestions would be appreciated.
From: Sean on
"Rachel " <racheyanna(a)hotmail.com> wrote in message <i2336a$o3$1(a)fred.mathworks.com>...
> Background: I work in a lab that uses the playrec MEX file to access the soundcard via an ASIO driver. This lab uses playrec to present stimuli (audio signals) and record responses (audio signals) from human ears. We've written a function that calls playrec within a loop ("stimulus loop") that is incremented until the number of desired averages is obtained. We have a plot that is updated as each average is obtained, so within the stimulus loop, there are several subfunctions being called.
> Specific question: We want to have the ability to pause within the stimulus loop IF NECESSARY (i.e. subjects need a break--we will be testing children who are less predictable than adults). We DON'T want to the function to ask us for an input after each repetition--we want the loop to continue UNLESS we give it an input.
> We're having difficulty figuring out how to do this, and any suggestions would be appreciated.

Use a GUI with a few buttons.

Here's an example: the GUI,written in GUIDE has 4 buttons pauseButton, stopButton,startButton,goButton.

function goButton_Callback(hObject, eventdata, handles)
setappdata(0,'GO',1)


% --- Executes on button press in pauseButton.
function pauseButton_Callback(hObject, eventdata, handles)
setappdata(0,'GO',0)


function startfun()
i = 0;
STOP = getappdata(0,'STOP');
GO = getappdata(0,'GO');
while ~STOP
drawnow;
if GO
pause(0.5); %Only so the screen doesn't blow up with Hello Worlds
disp('Hello World');
i = i+1 %shows i on every iteration so you can see that it doesn't reset
end
GO = getappdata(0,'GO');
STOP = getappdata(0,'STOP');
end


% --- Executes on button press in startButton.
function startButton_Callback(hObject, eventdata, handles)

setappdata(0,'GO',1)
setappdata(0,'STOP',0)
startfun;


% --- Executes on button press in stopButton.
function stopButton_Callback(hObject, eventdata, handles)
setappdata(0,'STOP',1)