How can create a function with floating median?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tamilselvam Gunasekaran
am 19 Feb. 2016
Kommentiert: Tamilselvam Gunasekaran
am 23 Feb. 2016
Hello, I have a data with 24 hour continuous RR interval (distance between consecutive heart beats)data and i am trying to create a function that would obtain floating averages for different time durations. Ideally i would like to have a floating median rather than average since the data is non normally distributed. I am having hard time for some reason to create median float. I was wondering if some one would be able to help me out in changing the average float function to median float function. Thanks Tamil
function [avge,stdeviation,pnts,timesampl]=avgfloat(data,timestep,tstart)
% timestep is a vector containing the series of time intervals of interest
% in hr (converted to seconds)
timestep=timestep*3600;
% data is the data
% figure out how many timesteps were entered
l=length(timestep);
% calculate total time elapsed (s) during test (ignoring first data point)
time=zeros(length(data),1);
for i=2:length(data)
time(i)=time(i-1)+data(i);
end
% calcuate number of given time intervals in test
pntstop=floor(time(length(time))./timestep);
for i=1:l
% initialize start variable
strt=1;
for j=1:pntstop(i)
% find index of end of next timestep
n=find(time>=timestep(i)*j,1);
% find number of points that includes
pnts{i}(j)=n-strt+1;
% find average over that time interval
avge{i}(j)=sum(data(strt:n))/length(data(strt:n));
% find standard deviation over that time interval
stdeviation{i}(j)=std(data(strt:n));
% define what time range the sample represents
timesampl{i}(j)=time(floor((n+strt)/2))+tstart*3600;
% update start variable
strt=n+1;
% shift data to align with hours of day
if timesampl{i}(j)>=24*3600
timesampl{i}(j)=timesampl{i}(j)-24*3600;
elseif timesampl{i}(j)>=48*3600
timesampl{i}(j)=timesampl{i}(j)-48*3600;
end
end
end
5 Kommentare
Guillaume
am 23 Feb. 2016
Bearbeitet: Guillaume
am 23 Feb. 2016
Bear in mind that most of us don't work in the same field as you do, so expressions like 'holter recording HR information' may not mean anything to us.
As input to your function you appear to have two vectors, data that I assume represents some signal, and timestep that obviously represents some time. Yet, early on, you have
time(i) = time(i-1) + data(i);
Is that correct? The data also represents some time? What is its relationship with timestep?
Note that the above could be achieved more simply without a loop as:
time = cumsum([0 data(2:end)]);
It also begs the question, why is data(1) discarded?
Akzeptierte Antwort
Jos (10584)
am 23 Feb. 2016
% find MEDIAN over that time interval
MyMedian{i}(j)=median(data(strt:n));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!