Averaging Intervals on a Graph

2 views (last 30 days)
Rachel Hillner
Rachel Hillner on 29 Nov 2020
Answered: Rohit Pappu on 30 Dec 2020
I am trying to find the mean HR, BR, and GSR for certian time intervals from a plot where instantaneous HR, BR, GSR are plotted against HRTime, BRTime, and GSRTime respectively.
It seems as though the code I wrote for the meanBR and meanGSR work because there are about 204,000 entries whereas the HR only has about 3,000. The problem is that the correct intervals are not being averaged. For example, interval 1 starts at time 40428 and ends at time 40498. My code seems to be averaging the field entries 40428 : 40498 instead of the field entries corresponding to those said time intervals. Thus, the averages that it is calculating is incorrect and will not work for HR given there are only 3000 entries. Is there anyway to average the intervals corresponding to the times on the x-axis instead of in relation to the field entry number?
My Code:
meanTriggBR = zeros(17, 1);
meanTriggGSR = zeros(17, 1);
meanHR = zeros(17, 1);
for i = 1:length(TriggStartTime)-1
meanTriggBR(i) = mean(BR(TriggStartTime(i):TriggEndTime(i)));
meanTriggGSR(i) = mean(GSR(TriggStartTime(i):TriggEndTime(i)));
meanHR(i) = mean(HR(TriggStartTime(i):TriggEndTime(i)));
end

Answers (1)

Rohit Pappu
Rohit Pappu on 30 Dec 2020
If only the starting and ending time stamp need to be selected, the following syntax needs to be used
meanTriggBR = zeros(17, 1);
meanTriggGSR = zeros(17, 1);
meanHR = zeros(17, 1);
for i = 1:length(TriggStartTime)-1
%% Select elements in vector , corresponding to TriggStartTime(i) and TriggEndTime(i) position
meanTriggBR(i) = mean(BR(TriggStartTime(i),TriggEndTime(i)));
meanTriggGSR(i) = mean(GSR(TriggStartTime(i),TriggEndTime(i)));
meanHR(i) = mean(HR(TriggStartTime(i),TriggEndTime(i)));
end

Categories

Find more on Graph and Network Algorithms 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!