%Simple analog diaplay

figure(2)

%define the input
adaptor = 'winsound';
id = 0;
chan = 1;

% Analog input object Configuration.
% Create an analog input object with one channel.
ai = analoginput(adaptor, id);
ch = addchannel(ai, chan);

% Configure the analog input rate.
set(ai, 'SampleRate', 44100);

% Configure the analog input object to trigger manually.
set(ai, 'SamplesPerTrigger', 441); % 1/100 second
set(ai, 'TriggerRepeat', 1);
set(ai, 'TriggerType', 'manual');

% Object Execution.
% Start the analog input object.

for i=1:50
   
   %start data collection and trigger it
   start(ai);
   trigger(ai);
   
   % Obtain the available time and data.
   [data,time] = getdata(ai, ai.SamplesPerTrigger);
   
   stop(ai)
   
   %plot the data and set axes
   plot(time,data,'w');
   set(gca, 'XLim', [0 get(ai,'SamplesPerTrigger')/44100]);
   set(gca, 'YLim', [-1 1]);
   
   set(gca, 'color', [.1 .4 .2]);
   grid on
   
   % Label the plot.
   xlabel('Time (sec)');
   ylabel('Winsound.0 (Volts)');
   
   drawnow
end

delete(ai);
clf;