From: Phil on
I am trying to implement a TimerFcn for an analoginput object that plots some data every few hundred milliseconds, but I have been running into some odd behavior. I have simplified my code so it can be debugged by anyone that can create an analog input object using a winsound adaptor.

The main issue is that if I call the function bugtest nothing is plotted. However, if I place a dbstop on line 5 (start(data.ai)) and dbstep through, everything behaves as I would expect/like it. Is this a bug or is there something I am missing here.

Thanks!

function bugtest
chan=1;
data=localInitAI(chan);
set(data.ai, 'TimerFcn', @timercallbackfcn);
start(data.ai);
wait(10000);
stop(data.ai);


function [data]= localInitAI(chan)
%create analog input object
adaptor='winsound';id=0;
ai = analoginput(adaptor, id);
addchannel(ai, chan);
set(ai, 'SamplesPerTrigger', 20000);
set(ai, 'TimerPeriod', .2);
data.ai=ai;


function timercallbackfcn(obj,event);
%plot some data
bar(rand);
From: Sherryl Radbil on
When I run your code I do get the plot but get an error:

>> bugtest
??? Undefined function or method 'wait' for input arguments of type 'double'.

Error in ==> bugtest at 6
wait(10000);

Call wait for the ai object:

wait(ai, 10000)