MATLAB Answers

Delete first row matrix and records new value

2 views (last 30 days)
Teresa Carneiro
Teresa Carneiro on 7 Jul 2021
Commented: Teresa Carneiro on 8 Jul 2021
Hey! I'm going to record data continuously, and acquire 1000samples/sec for 8 different channels (from a DAQ board). After 30 seconds I'll have a 30000x8 matriz and I'll need to average each column except for the first one. After averaging it I'll need to save that value, delete the first second of this acquired data (which means the first 1000 lines from the matrix) and move the whole matrix 1000 lines up, so I can record the next second worth of data (the next 1000 lines), and repeat this while I'm recording live data, for an undefined period of time.
Anyone know how I can do this? Mainly, delete the first 1000 rows, move the matrix up to start at line 1 again and record new data in the last 1000 lines that just became empty by moving the matrix up.
I'm very new to matlab and would really appreciate any kind of help.

Answers (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 7 Jul 2021
Have you read this documentation for DAQ tools and fcns of MATLAB:
Why not to collect all data for whole 30 sec or whatever time length, and then perform averaging or any necessary data processing. If this data processing has to be continuous for control purposes, then it is necessary.
  1 Comment
Teresa Carneiro
Teresa Carneiro on 8 Jul 2021
That's exactly what I want to do. But if I acquire data for, let's suppose, 5 minutes (300 seconds), I'll want to remove the average I measured in the first 30 sec to the sec 31 of my raw data. For the second 32 of my raw data I want to remove the average of data acquired betweent seconds 2:31 to the raw data. For the second 33 I want to remove the average of the lines data acquired betweent seconds 3:32. This is because I'll be measuring EEG signals and by averaging the data I get the noise of the signal, which I then remove from the raw signal.
Yes I've read that documentation, thanks. I'm using the GUI app tho. But acquiring data like this:
function dataCapture(src, ~, c, hGui)
[eventData, eventTimestamps] = read(src, src.ScansAvailableFcnCount, ...
'OutputFormat', 'Matrix');
persistent dataBuffer trigActive trigMoment filterBuffer
% If dataCapture is running for the first time, initialize persistent vars
if eventTimestamps(1)==0
dataBuffer = []; % data buffer
trigActive = false; % trigger condition flag
trigMoment = []; % data timestamp when trigger condition met
prevData = []; % last data point from previous callback execution
else
prevData = dataBuffer(end, :);
end
% Store continuous acquisition timestamps and data in persistent FIFO
% buffer dataBuffer
latestData = [eventTimestamps, eventData];
dataBuffer = [dataBuffer; latestData];
numSamplesToDiscard = size(dataBuffer,1) - c.bufferSize;
if (numSamplesToDiscard > 0)
dataBuffer(1:numSamplesToDiscard, :) = [];
end

Sign in to comment.


Soniya Jain
Soniya Jain on 7 Jul 2021
  1. To find mean of matrix, you can refer Matlab documentation: https://in.mathworks.com/help/matlab/ref/mean.html
  2. What do you mean by moving the matrix up? If you want to delete the 1st 1000 rows, you can overwrite it. And you can use loop to record new data every time
  3. To learn more about Matlab, you can refer Matlab Onramp Course.
  1 Comment
Teresa Carneiro
Teresa Carneiro on 8 Jul 2021
I can not overwrite it because for the next second of data I'll need to keep the last seconds data, I need to constantly delete the first second of data I've recorded. This means that I'll acquire 1:30 seconds of data, but then I need the next 2:31. Do you get what I'm saying?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by