Path: news.mathworks.com!not-for-mail
From: "Sean de " <sean.dewolski@nospamplease.umit.maine.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Data Subsampling
Date: Tue, 23 Nov 2010 20:08:04 +0000 (UTC)
Organization: University of Maine
Lines: 37
Message-ID: <ich6v4$flh$1@fred.mathworks.com>
References: <ich2vm$mbl$1@fred.mathworks.com> <ich5cg$22r$1@fred.mathworks.com> <ich6cc$6j9$1@fred.mathworks.com>
Reply-To: "Sean de " <sean.dewolski@nospamplease.umit.maine.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1290542884 16049 172.30.248.38 (23 Nov 2010 20:08:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 23 Nov 2010 20:08:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2256903
Xref: news.mathworks.com comp.soft-sys.matlab:689432

"Billy Bob" <jforwin@gmail.com> wrote in message <ich6cc$6j9$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ich5cg$22r$1@fred.mathworks.com>...
> > "Billy Bob" <jforwin@gmail.com> wrote in message <ich2vm$mbl$1@fred.mathworks.com>...
> > > Hi 
> > > I have a relatively simple problem that I can't figure out an elegant way to solve.
> > > 
> > > I have a data set consisting of:
> > > 
> > > Column 1: a series of days numbered 1 to 365 or 366 for each year from 1974 until now
> > > Column 2: average daily temperature on each day
> > > 
> > > What I would like to do is to produce a matrix of years (x), days (y) and temperature (z). So far I have been able to do this for Day 1 for all years using a combination of row and column indices but I am unsure of how to this for all days across all years. Any help would be greatly appreciated.
> > > 
> > > Thanks.
> > - - - - - - - - - - -
> >  Let A be your present data set array.
> > 
> >  B = [cumsum([false;diff(A(:,1))<0])+1974,A];
> > 
> > Roger Stafford
> 
> Thanks for this Roger and Sean
> So what I have now is each day correctly labeled with the year (Columns 1 (Year) and 2 (Day) ) and temperature in Column 3.
> 
> What I would like to do is separate out each year with it's associated temperature data for the 37 year data record, I guess using the year as marker (to take into account Leap Years) ? Any advice on how to do this?
> 
> Thanks for the help on what are undoubtedly pretty silly questions! 

data(:,1) = data(:,1)-min(data(:,1))+1; %normalize so 1974 is 1

new_data_matrix = accumarray(data(:,[1 2]),data(:,3));

each row of the new matrix will be the year (1:37) and the columns will be the 366 days.

You could also do:
new_data_matrix = zeros(37,366);
new_data_matrix(sub2ind([37 366],data(:,1),data(:,2))) = data(:,3);