Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Flexible/sporadic pausing within a loop

Subject: Flexible/sporadic pausing within a loop

From: Rachel

Date: 20 Jul, 2010 02:55:07

Message: 1 of 2

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.

Subject: Flexible/sporadic pausing within a loop

From: Sean

Date: 20 Jul, 2010 14:15:04

Message: 2 of 2

"Rachel " <racheyanna@hotmail.com> wrote in message <i2336a$o3$1@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)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us