How can I calculate trapz value based on an event counter and then plot it?
2 views (last 30 days)
the following lines of code should implement a calculation of an integral for certain events in the data.
The very first colum is the time, the second the corresponding value and the third column the event counter.
The values are saved in the integ_mtrx. It worked with cumtrapz, but i am having my problems with the trapz function.
Here the events 0 should be calculated. Events with 0 in the second colum shouldn't be calculated ( like event 1,2,3,4,..)
for every event the integral should be calculated:
for i= 0:(vzwcounter)
temp = Integ_MTRX(Integ_MTRX(:,3)==i,:);
Jan on 15 Sep 2022
As far as I understand your code was almost working. I added an if condition to skip scalar data and shifted the index for the output B by 1 because 0 is no valid index in Matlab:
B = nan(1, vzwcounter + 1);
for k = 0:vzwcounter
temp = Integ_MTRX(Integ_MTRX(:, 3) == k, :);
if size(temp, 1) > 1
B(k + 1) = trapz(temp(:, 1), temp(:, 2), 1);