Averaging Intervals on a Graph

2 次查看(过去 30 天)
Rachel Hillner
Rachel Hillner 2020-11-29
回答: Rohit Pappu 2020-12-30
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

回答(1 个)

Rohit Pappu
Rohit Pappu 2020-12-30
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

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by