Plotting continuous data from A/D converter
Show older comments
I am using the session interface of Data Acq Toolbox to continuously take samples from a NIDAQ. I have created a listener, so that periodically the collected data is written to a file. At the same time, without stopping data collection, I want the ability to plot the data.
My code does this--but there is a gap in the plot between every call to the listener service routine. The data correctly plots to the same axes, but the subsequent plots are not connected. I have tried various permutations of hold, but none seem to do what I want. Here's the relevant code:
MATLAB code
% --- Processes incoming samples as they are available
function processData(src,data,fid,hObject)
% We have a block of samples
nsamp = size(data.Data,1);
numchans = size(data.Data,2);
handles=guidata(hObject);
for i=1:nsamp
fprintf(fid,'%6.4f ',data.TimeStamps(i));
for j=1:numchans
fprintf(fid,'%2.4f ',data.Data(i,j));
end
fprintf(fid,'\n');
end
if (handles.doPlot)
plot(handles.axes1,data.TimeStamps,data.Data(:,handles.sel_index));
% if first time, add the legend
if(handles.newplot)
legend(handles.axes1,handles.sel_legend);
handles.newplot=false;
guidata(hObject,handles);
end
end
Here's the result (notice the gap around 20 sec):

Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!