Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
help indexing by date

Subject: help indexing by date

From: david

Date: 2 Jun, 2011 07:58:05

Message: 1 of 3

Hi,

I'm trying to divide an MxN matrix into multiple matrices of PxN matrices, where P varies and is based upon a day count, where the 1st column in the original matrix is a vector of dates in numeric format containing year, day, month, hour and minute.

so for example I have a 15000x7 matrix which is 12 days of data.
I want to create matrices that contain 6 days of data, so the first one will be say 2480x7, and only contain the elements that corespond to the first 6 days of data, then the next one may be 2520x7,containing the elements that corespond to the data from 2 to 7.

I could do this easy enough if there was an equal number of data points for each day, but there is not.

Anyone got any idea how I could do this?

Thanks in advance for any help.
David

Subject: help indexing by date

From: Baalzamon

Date: 2 Jun, 2011 10:18:05

Message: 2 of 3

I did a similar thing last year. Basically I had a file with YY MM DD HH MM in columns and the data in rows. In any given day the number of entries could vary..

Two ways I did it were
(i) took the cells with the date and converted them to date number

(ii) linear indexing within a for loop
as I always wanted a row then
z=a(a(:,vector)==i,:)
where a is the input, vector is the column you are searching for and i is the value...

e.g.
counter =1;
output=[];
for i=min(a(:,year_column)):1:max(a(:,year_column))
z{counter}=a(a(:,year_column)==i,:);
counter =counter +1;
end;

So here you end up with all entries for a given year in a nested cell which you can extract as and when...


>> Not checked >>

So i guess you need something similar but maybe pass the values into a nested cell....

Subject: help indexing by date

From: david

Date: 2 Jun, 2011 15:16:19

Message: 3 of 3

Thanks for the help, I actually fond another way of performing the task, doing the following:
InDate=dates;
prevYear = datenum(year(InDate)-1, 12,31);
dayOfYear = InDate-prevYear;
dates2=floor(dayOfYear);

That gives the dates in terms of the day of the year, from there is was simly a matter of using ismember to allocate them to the right place!


"Baalzamon " <baalzamon_moridin@yahoo.com> wrote in message <is7o0t$qsu$1@newscl01ah.mathworks.com>...
> I did a similar thing last year. Basically I had a file with YY MM DD HH MM in columns and the data in rows. In any given day the number of entries could vary..
>
> Two ways I did it were
> (i) took the cells with the date and converted them to date number
>
> (ii) linear indexing within a for loop
> as I always wanted a row then
> z=a(a(:,vector)==i,:)
> where a is the input, vector is the column you are searching for and i is the value...
>
> e.g.
> counter =1;
> output=[];
> for i=min(a(:,year_column)):1:max(a(:,year_column))
> z{counter}=a(a(:,year_column)==i,:);
> counter =counter +1;
> end;
>
> So here you end up with all entries for a given year in a nested cell which you can extract as and when...
>
>
> >> Not checked >>
>
> So i guess you need something similar but maybe pass the values into a nested cell....

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us