http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178
MATLAB Central Newsreader  Data Subsampling
Feed for thread: Data Subsampling
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Tue, 23 Nov 2010 19:00:06 +0000
Data Subsampling
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178#798734
Billy Bob
Hi <br>
I have a relatively simple problem that I can't figure out an elegant way to solve.<br>
<br>
I have a data set consisting of:<br>
<br>
Column 1: a series of days numbered 1 to 365 or 366 for each year from 1974 until now<br>
Column 2: average daily temperature on each day<br>
<br>
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.<br>
<br>
Thanks.

Tue, 23 Nov 2010 19:19:04 +0000
Re: Data Subsampling
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178#798737
Sean de
"Billy Bob" <jforwin@gmail.com> wrote in message <ich2vm$mbl$1@fred.mathworks.com>...<br>
> Hi <br>
> I have a relatively simple problem that I can't figure out an elegant way to solve.<br>
> <br>
> I have a data set consisting of:<br>
> <br>
> Column 1: a series of days numbered 1 to 365 or 366 for each year from 1974 until now<br>
> Column 2: average daily temperature on each day<br>
> <br>
> 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.<br>
> <br>
> Thanks.<br>
<br>
It sounds like ACCUMARRAY might be what you want. Feed it your days/years as subs, [days years], and the temperatures as vals, [T]. It'll then place all of the T's in their respective positions.

Tue, 23 Nov 2010 19:41:04 +0000
Re: Data Subsampling
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178#798745
Roger Stafford
"Billy Bob" <jforwin@gmail.com> wrote in message <ich2vm$mbl$1@fred.mathworks.com>...<br>
> Hi <br>
> I have a relatively simple problem that I can't figure out an elegant way to solve.<br>
> <br>
> I have a data set consisting of:<br>
> <br>
> Column 1: a series of days numbered 1 to 365 or 366 for each year from 1974 until now<br>
> Column 2: average daily temperature on each day<br>
> <br>
> 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.<br>
> <br>
> Thanks.<br>
          <br>
Let A be your present data set array.<br>
<br>
B = [cumsum([false;diff(A(:,1))<0])+1974,A];<br>
<br>
Roger Stafford

Tue, 23 Nov 2010 19:58:04 +0000
Re: Data Subsampling
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178#798748
Billy Bob
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ich5cg$22r$1@fred.mathworks.com>...<br>
> "Billy Bob" <jforwin@gmail.com> wrote in message <ich2vm$mbl$1@fred.mathworks.com>...<br>
> > Hi <br>
> > I have a relatively simple problem that I can't figure out an elegant way to solve.<br>
> > <br>
> > I have a data set consisting of:<br>
> > <br>
> > Column 1: a series of days numbered 1 to 365 or 366 for each year from 1974 until now<br>
> > Column 2: average daily temperature on each day<br>
> > <br>
> > 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.<br>
> > <br>
> > Thanks.<br>
>           <br>
> Let A be your present data set array.<br>
> <br>
> B = [cumsum([false;diff(A(:,1))<0])+1974,A];<br>
> <br>
> Roger Stafford<br>
<br>
Thanks for this Roger and Sean<br>
So what I have now is each day correctly labeled with the year (Columns 1 (Year) and 2 (Day) ) and temperature in Column 3.<br>
<br>
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?<br>
<br>
Thanks for the help on what are undoubtedly pretty silly questions!

Tue, 23 Nov 2010 20:08:04 +0000
Re: Data Subsampling
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178#798752
Sean de
"Billy Bob" <jforwin@gmail.com> wrote in message <ich6cc$6j9$1@fred.mathworks.com>...<br>
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ich5cg$22r$1@fred.mathworks.com>...<br>
> > "Billy Bob" <jforwin@gmail.com> wrote in message <ich2vm$mbl$1@fred.mathworks.com>...<br>
> > > Hi <br>
> > > I have a relatively simple problem that I can't figure out an elegant way to solve.<br>
> > > <br>
> > > I have a data set consisting of:<br>
> > > <br>
> > > Column 1: a series of days numbered 1 to 365 or 366 for each year from 1974 until now<br>
> > > Column 2: average daily temperature on each day<br>
> > > <br>
> > > 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.<br>
> > > <br>
> > > Thanks.<br>
> >           <br>
> > Let A be your present data set array.<br>
> > <br>
> > B = [cumsum([false;diff(A(:,1))<0])+1974,A];<br>
> > <br>
> > Roger Stafford<br>
> <br>
> Thanks for this Roger and Sean<br>
> So what I have now is each day correctly labeled with the year (Columns 1 (Year) and 2 (Day) ) and temperature in Column 3.<br>
> <br>
> 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?<br>
> <br>
> Thanks for the help on what are undoubtedly pretty silly questions! <br>
<br>
data(:,1) = data(:,1)min(data(:,1))+1; %normalize so 1974 is 1<br>
<br>
new_data_matrix = accumarray(data(:,[1 2]),data(:,3));<br>
<br>
each row of the new matrix will be the year (1:37) and the columns will be the 366 days.<br>
<br>
You could also do:<br>
new_data_matrix = zeros(37,366);<br>
new_data_matrix(sub2ind([37 366],data(:,1),data(:,2))) = data(:,3);

Tue, 23 Nov 2010 20:32:04 +0000
Re: Data Subsampling
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178#798763
Billy Bob
"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ich6v4$flh$1@fred.mathworks.com>...<br>
> "Billy Bob" <jforwin@gmail.com> wrote in message <ich6cc$6j9$1@fred.mathworks.com>...<br>
> > "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ich5cg$22r$1@fred.mathworks.com>...<br>
> > > "Billy Bob" <jforwin@gmail.com> wrote in message <ich2vm$mbl$1@fred.mathworks.com>...<br>
> > > > Hi <br>
> > > > I have a relatively simple problem that I can't figure out an elegant way to solve.<br>
> > > > <br>
> > > > I have a data set consisting of:<br>
> > > > <br>
> > > > Column 1: a series of days numbered 1 to 365 or 366 for each year from 1974 until now<br>
> > > > Column 2: average daily temperature on each day<br>
> > > > <br>
> > > > 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.<br>
> > > > <br>
> > > > Thanks.<br>
> > >           <br>
> > > Let A be your present data set array.<br>
> > > <br>
> > > B = [cumsum([false;diff(A(:,1))<0])+1974,A];<br>
> > > <br>
> > > Roger Stafford<br>
> > <br>
> > Thanks for this Roger and Sean<br>
> > So what I have now is each day correctly labeled with the year (Columns 1 (Year) and 2 (Day) ) and temperature in Column 3.<br>
> > <br>
> > 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?<br>
> > <br>
> > Thanks for the help on what are undoubtedly pretty silly questions! <br>
> <br>
> data(:,1) = data(:,1)min(data(:,1))+1; %normalize so 1974 is 1<br>
> <br>
> new_data_matrix = accumarray(data(:,[1 2]),data(:,3));<br>
> <br>
> each row of the new matrix will be the year (1:37) and the columns will be the 366 days.<br>
> <br>
> You could also do:<br>
> new_data_matrix = zeros(37,366);<br>
> new_data_matrix(sub2ind([37 366],data(:,1),data(:,2))) = data(:,3);<br>
<br>
Thanks Sean  what I get with the first approach is a matrix of zeros from Row 0 to 1973 by 366 columns and then the data appears. Is there a way to get Matlab to ignore Rows 0 to 1973? Thanks for your help.

Tue, 23 Nov 2010 20:39:05 +0000
Re: Data Subsampling
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178#798765
Sean de
<br>
> > data(:,1) = data(:,1)min(data(:,1))+1; %normalize so 1974 is 1<br>
> > <br>
> > new_data_matrix = accumarray(data(:,[1 2]),data(:,3));<br>
> > <br>
> > each row of the new matrix will be the year (1:37) and the columns will be the 366 days.<br>
> > <br>
> > You could also do:<br>
> > new_data_matrix = zeros(37,366);<br>
> > new_data_matrix(sub2ind([37 366],data(:,1),data(:,2))) = data(:,3);<br>
> <br>
> Thanks Sean  what I get with the first approach is a matrix of zeros from Row 0 to 1973 by 366 columns and then the data appears. Is there a way to get Matlab to ignore Rows 0 to 1973? Thanks for your help.<br>
<br>
That was the point of this line. It makes the year 1974 = 1, thus making it the first row.<br>
<br>
data(:,1) = data(:,1)min(data(:,1))+1; %normalize so 1974 is 1

Tue, 23 Nov 2010 21:09:04 +0000
Re: Data Subsampling
http://www.mathworks.com/matlabcentral/newsreader/view_thread/297178#798779
Billy Bob
"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ich8p9$fgj$1@fred.mathworks.com>...<br>
> <br>
> > > data(:,1) = data(:,1)min(data(:,1))+1; %normalize so 1974 is 1<br>
> > > <br>
> > > new_data_matrix = accumarray(data(:,[1 2]),data(:,3));<br>
> > > <br>
> > > each row of the new matrix will be the year (1:37) and the columns will be the 366 days.<br>
> > > <br>
> > > You could also do:<br>
> > > new_data_matrix = zeros(37,366);<br>
> > > new_data_matrix(sub2ind([37 366],data(:,1),data(:,2))) = data(:,3);<br>
> > <br>
> > Thanks Sean  what I get with the first approach is a matrix of zeros from Row 0 to 1973 by 366 columns and then the data appears. Is there a way to get Matlab to ignore Rows 0 to 1973? Thanks for your help.<br>
> <br>
> That was the point of this line. It makes the year 1974 = 1, thus making it the first row.<br>
> <br>
> data(:,1) = data(:,1)min(data(:,1))+1; %normalize so 1974 is 1<br>
<br>
<br>
That's great. Thanks for your help Sean.