"If" statements for NI daq functions!? Help?

Hi all,
I am trying to get matlab to output some signals via my NI card, but I would like to turn on and off the signal via a timer using "if" statements.
For example,
experimentStartTime = tic;
niSession = daq.createSession('ni');
niSession.addAnalogOutputChannel('dev1','ao0','voltage');
niSession.queueOutputData([stimulus']);
stimStartTime = toc;
if toc-stimStartTime < 5
niSession.startBackground();
elseif toc-stimStartTime > 5
niSession.stop()
end
However, MATLAB doesnt seem to run through the if loops and stop the analog Output. Any help would be great. Thanks!

 Accepted Answer

You need to make experimentStartTime a "persistent" variable so it will retain its value each time you enter this timer callback. Right now you're resetting it with tic each time and so "toc-stimStartTime" never gets very big.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!