Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Summarizing yearly/monthly data in time series
Date: Wed, 4 Nov 2009 19:55:21 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 19
Message-ID: <hcsm79$79a$1@fred.mathworks.com>
References: <hcaam2$8dv$1@fred.mathworks.com> <hcslce$e15$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257364521 7466 172.30.248.38 (4 Nov 2009 19:55:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 19:55:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:582505


> year_selected = 2009;
> month_selected = 11;
> 
> matched = data(:,1)==selected & data(:,2)==month_selected;
> sumdata = sum(data(matched,4))

May be ISMEMBER syntax is clearer than FIND

data=[2009 11 01 1;
          2008 10 02 2;
          2009 11 02 3]

year_selected = 2009;
month_selected = 11;

matched = ismember(data(:,[1 2]), [year_selected month_selected], 'rows');
sumdata = sum(data(matched,4))

Bruno