The_Nez
The_Nez

Reputation: 13

Matlab Timing Program

For work, I need to write a Matlab program that will trigger a stimulus (TTL pulse) after set amounts of time. First, I need the program to wait 32 mins. Then, I want it to execute the stimulus pulse, wait 5 seconds, execute the stimulus pulse again, then wait an additional 115 seconds. I need it to do 5 iterations of this (excluding the 32 min wait period).

I am terrible at Matlab syntax. I worked with Python a little bit, but this particular function requires Matlab because it has a toolkit that works with the stimulus generator.

For what it's worth, the trigger output as it appears in existing code looks like this:

if i > 1
    % insert output trigger for page 1
    pages(1).Page = 1 + VSG.DUALPAGE + VSG.TRIGGERPAGE;
  end;

Here's my crappy attempt at the loop part of the code, which is giving me all kinds of syntax errors:

% Use for loop for 5 iterations
for i = 1:5
    % trigger TTL pulse
    pages(1).Page = 1 + VSG.DUALPAGE + VSG.TRIGGERPAGE;
    % trying to use tic and toc as a timer that resets each iteration
    timerID = tic;
    % I thought to use a while loop for the timing
    % 5 second wait period
    while true
        if(toc(timerID)>5)
            break;
        end
    % trigger TTL pulse again
    pages(1).Page = 1 + VSG.DUALPAGE + VSG.TRIGGERPAGE;
    % 115 second wait period
    while true
        if(toc(timerID)>120)
            break;
        end
end

That's all I've got. Any help at all would be greatly appreciated. Feel free to tell me if I need to use a completely different approach as I know I'm terrible at Matlab. Thank you.

Upvotes: 1

Views: 63

Answers (1)

Stewie Griffin
Stewie Griffin

Reputation: 14939

You can use pause for this. Try something like this:

pause(32*60);  % Pause 32 minutes
for ii = 1:5
   pages(1).Page = 1 + VSG.DUALPAGE + VSG.TRIGGERPAGE;
   pause(5);
   pages(1).Page = 1 + VSG.DUALPAGE + VSG.TRIGGERPAGE;
   pause(115);
end

Upvotes: 1

Related Questions