Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Nonuniform time moving window average
Date: Tue, 12 May 2009 19:50:18 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 20
Message-ID: <gucjtq$ajt$1@fred.mathworks.com>
References: <guci52$fku$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242157818 10877 172.30.248.35 (12 May 2009 19:50:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 12 May 2009 19:50:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:539405


Please try this:

% Data
time = 0:0.1:10;
time([5 25:28 45 60:62 90]) = []; %Simulated data drops
data = rand(size(time));
dt =1;

% Engine
n=length(time);
lastfirst = n; % alternatively: find(time<=time(end)-dt,1,'last');
first=1:lastfirst;
tlast = time(first)+dt;
last = interp1(time,1:n,tlast,'linear','extrap');
last = max(min(floor(last),n),first);
%
csdata = cumsum([0 data]);
windowAve = (csdata(last+1)-csdata(first))./(last-first+1)

% Bruno