| Data Acquisition Toolbox | ![]() |
Example: Queuing Data with putdata
This example illustrates how you can use putdata to queue 8000 samples, and then output the data a total of five times using the RepeatOutput property.
You can run this example by typing daqdoc6_3 at the MATLAB command line.
1. Create a device object - Create the analog output object AO for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo.
AO = analogoutput('winsound');
%AO = analogoutput('nidaq',1);
%AO = analogoutput('cbi',1);
2. Add channels - Add one channel to AO.
chans = addchannel(AO,1); %chans = addchannel(AO,0); % For NI and CBI
3. Configure property values - Define an output time of one second, assign values to the basic setup properties, generate data to be queued, and issue two putdata calls. Since the queued data is repeated four times and two putdata calls are issued, a total of 10 seconds of data is output.
duration = 1; set(AO,'SampleRate',8000) ActualRate = get(AO,'SampleRate'); len = ActualRate*duration; set(AO,'RepeatOutput',4) data = sin(linspace(0,2*pi,len))'; putdata(AO,data) putdata(AO,data)
4. Output data - Start AO and wait for the device object to stop running.
start(AO) while strcmp(AO.Running,'On') end
5. Clean up - When you no longer need AO, you should remove it from memory and from the MATLAB workspace.
delete(AO) clear AO
| Queuing Data with putdata | Configuring Analog Output Triggers | ![]() |