From: John D'Errico on
Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <8379722f-95bb-4ebb-99a7-5c6b024ac0c4(a)z33g2000vbb.googlegroups.com>...
> On May 31, 11:18 pm, "John D'Errico" <woodch...(a)rochester.rr.com>
> wrote:
> > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <357ca75a-8456-4100-9362-4e6c775cf...(a)e21g2000vbl.googlegroups.com>...
> > > Hi all,
> >
> > > Here are the data I am working on:
> >
> > > dDataTmp2 is a  Nx2 matrix, with the first column being the timestamps
> > > and the second column the data.
> >
> > > K>> datestr(dDataTmp2(1, 1))
> >
> > > ans =
> >
> > > 01-Apr-2010 00:19:00
> >
> > > I would like to compute the average of the second-column-data every M
> > > seconds, e.g. M=5, and put the results into a new smaller matrix.
> >
> > > Of course I can do datestr on each timestamp and match the "seconds",
> > > but that's slow and I have to do this repetitively and iteratively on
> > > GB of data.
> >
> > > So the faster approach is to directly operate on the date/time
> > > numbers; but I don't know how to operate on them.
> >
> > > Anybody could think of some "the fastest" algorithms for this?
> >
> > > Thank you!
> >
> > Use my consolidator function, keying on the
> > indicator:
> >
> >     floor(timestamps*24*60*12)
> >
> > for your averaging. This allows you to not worry
> > if the data is equally or unequally spaced.
> >
> > Find consolidator on the FEX:
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/8354
> >
> > HTH,
> > John
>
> Hi John,
>
> Thanks a lot! But after reading the help of Consolidator, I just
> couldn't figure out how to use it in the right way to solve my
> problem.
>
> Could you please elaborate a bit further?

What is the problem?

[~,averages] = consolidator(floor(dDataTmp2(:,1)*24*60*12),dDataTmp2(:,2));

John
From: Luna Moon on
On Jun 1, 10:37 am, "John D'Errico" <woodch...(a)rochester.rr.com>
wrote:
> Luna Moon <lunamoonm...(a)gmail.com> wrote in message <8379722f-95bb-4ebb-99a7-5c6b024ac...(a)z33g2000vbb.googlegroups.com>...
> > On May 31, 11:18 pm, "John D'Errico" <woodch...(a)rochester.rr.com>
> > wrote:
> > > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <357ca75a-8456-4100-9362-4e6c775cf...(a)e21g2000vbl.googlegroups.com>...
> > > > Hi all,
>
> > > > Here are the data I am working on:
>
> > > > dDataTmp2 is a  Nx2 matrix, with the first column being the timestamps
> > > > and the second column the data.
>
> > > > K>> datestr(dDataTmp2(1, 1))
>
> > > > ans =
>
> > > > 01-Apr-2010 00:19:00
>
> > > > I would like to compute the average of the second-column-data every M
> > > > seconds, e.g. M=5, and put the results into a new smaller matrix.
>
> > > > Of course I can do datestr on each timestamp and match the "seconds",
> > > > but that's slow and I have to do this repetitively and iteratively on
> > > > GB of data.
>
> > > > So the faster approach is to directly operate on the date/time
> > > > numbers; but I don't know how to operate on them.
>
> > > > Anybody could think of some "the fastest" algorithms for this?
>
> > > > Thank you!
>
> > > Use my consolidator function, keying on the
> > > indicator:
>
> > >     floor(timestamps*24*60*12)
>
> > > for your averaging. This allows you to not worry
> > > if the data is equally or unequally spaced.
>
> > > Find consolidator on the FEX:
>
> > >http://www.mathworks.com/matlabcentral/fileexchange/8354
>
> > > HTH,
> > > John
>
> > Hi John,
>
> > Thanks a lot! But after reading the help of Consolidator, I just
> > couldn't figure out how to use it in the right way to solve my
> > problem.
>
> > Could you please elaborate a bit further?
>
> What is the problem?
>
> [~,averages] = consolidator(floor(dDataTmp2(:,1)*24*60*12),dDataTmp2(:,2));
>
> John

Okay, now I think I understand the usage.

One further question: is there a way to do "linear regression" using
consolidator?

For example,

there are two sets of data now,

timestamps is a linear array of timestamps (irregularly spaced);

datax is a linear array of data corresponding to "timestamps";

datay is a linear array of data corresponding to "timestamps";

I would like to do linear regression of datay on datax for each day of
timestamps,

using the Matlab function day(timestamps) I will obtain the
indicators,

but what's the fastest way of doing linear regression according to the
days?

The key is speed.

Thank you very much...


From: Luna Moon on
On Jun 1, 10:37 am, "John D'Errico" <woodch...(a)rochester.rr.com>
wrote:
> Luna Moon <lunamoonm...(a)gmail.com> wrote in message <8379722f-95bb-4ebb-99a7-5c6b024ac...(a)z33g2000vbb.googlegroups.com>...
> > On May 31, 11:18 pm, "John D'Errico" <woodch...(a)rochester.rr.com>
> > wrote:
> > > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <357ca75a-8456-4100-9362-4e6c775cf...(a)e21g2000vbl.googlegroups.com>...
> > > > Hi all,
>
> > > > Here are the data I am working on:
>
> > > > dDataTmp2 is a  Nx2 matrix, with the first column being the timestamps
> > > > and the second column the data.
>
> > > > K>> datestr(dDataTmp2(1, 1))
>
> > > > ans =
>
> > > > 01-Apr-2010 00:19:00
>
> > > > I would like to compute the average of the second-column-data every M
> > > > seconds, e.g. M=5, and put the results into a new smaller matrix.
>
> > > > Of course I can do datestr on each timestamp and match the "seconds",
> > > > but that's slow and I have to do this repetitively and iteratively on
> > > > GB of data.
>
> > > > So the faster approach is to directly operate on the date/time
> > > > numbers; but I don't know how to operate on them.
>
> > > > Anybody could think of some "the fastest" algorithms for this?
>
> > > > Thank you!
>
> > > Use my consolidator function, keying on the
> > > indicator:
>
> > >     floor(timestamps*24*60*12)
>
> > > for your averaging. This allows you to not worry
> > > if the data is equally or unequally spaced.
>
> > > Find consolidator on the FEX:
>
> > >http://www.mathworks.com/matlabcentral/fileexchange/8354
>
> > > HTH,
> > > John
>
> > Hi John,
>
> > Thanks a lot! But after reading the help of Consolidator, I just
> > couldn't figure out how to use it in the right way to solve my
> > problem.
>
> > Could you please elaborate a bit further?
>
> What is the problem?
>
> [~,averages] = consolidator(floor(dDataTmp2(:,1)*24*60*12),dDataTmp2(:,2));
>
> John

Hi John,

I have tried consolidator and it went great!Thank you!

However, I have further questions regarding the usage of
consolidator.

Let's say in the 5 seconds interval, for example:

09:00:00 15
09:00:00 3
09:00:01 2
09:00:01 6
09:00:02 5
09:00:03 4
09:00:04 3
09:00:04 10
09:00:04 20

How do I obtain the number occurring at the very first timestamp.

In the above 5-second interval, the result would be 15.

Similarly, how do I obtain the number occurring at the very last
timestamp, e.g. 20 in the above 5-second interval.

---------

Is there a way to call "Consolidator" once, and remember and store the
"indexing structure" for later use?

As you can see, we need to call "consolidator" 5 times:

[~, firstnumber] = consolidator(floor(dDataTmp2(:,
1)*24*60*12),dDataTmp2(:,2), 'firstnumber');

[~, lasttnumber] = consolidator(floor(dDataTmp2(:,
1)*24*60*12),dDataTmp2(:,2), 'lastnumber');

[~, average] = consolidator(floor(dDataTmp2(:,1)*24*60*12),dDataTmp2(:,
2), 'average');

[~, max] = consolidator(floor(dDataTmp2(:,1)*24*60*12),dDataTmp2(:,2),
'max');

[~, min] = consolidator(floor(dDataTmp2(:,1)*24*60*12),dDataTmp2(:,2),
'min');


Any thoughts? Thank you for your help!