Max indices in for loop not changing after initial run (index exceeds the number or array elements)
Show older comments
I am getting the error
Warning: Error occurred while executing the listener callback for event ElementsAvailable defined for class daq.Buffer:
Index exceeds the number of array elements. Index must not exceed 3.
this error is occuring on my set function line in the code below. After pressing the "Start Button" on my UI(as seen below) and run it the first time after opening it it runs smoothly. after checking off additional channels it leads to errors. After the daq is done collecting and the user presses stop it writes the values to the workspace and I can see that it is still collecting those values even though they are not being displayed.

Any help is greatly appreciated!
function updateLivePlot(app)
if isempty(app.DataFIFOBufferch1) || isempty(app.SelectedChannels)
return
end
% Disable interactivity
disableDefaultInteractivity(app.LiveAxes);
% Keep the colors the same after each new data point
app.LiveAxes.ColorOrderIndex = 1;
if isempty(app.LivePlotLine)
% First-Time Setup
app.LivePlotLine = plot(app.LiveAxes, app.TimestampsFIFOBuffer, app.DataFIFOBufferch1(:,app.SelectedChannels));
else
% Update existing plot
for j = 1:numel(app.SelectedChannels)
disp(j)
% Check if the line needs to be extended
if any(j <= numel(app.LivePlotLine)) && isempty(app.LivePlotLine(j))
% Use existing axes to plot
app.LivePlotLine(j) = plot(app.LiveAxes, app.TimestampsFIFOBuffer, app.DataFIFOBufferch1(:, j));
else
% Update existing line
set(app.LivePlotLine(j), 'XData', app.TimestampsFIFOBuffer, 'YData', app.DataFIFOBufferch1(:, j));
end
end
end
if numel(app.TimestampsFIFOBuffer) > 1
xlim(app.LiveAxes, [app.TimestampsFIFOBuffer(1), app.TimestampsFIFOBuffer(end)]);
end
end
Accepted Answer
More Answers (1)
Connor
on 21 Mar 2024
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!