MATLAB Newsgroup

Hi everybody!

I'm sure there must be a very simple way to solve this problem but I'm still a relative novice to Matlab so I'd appreciate any help on this! Thanks in advance to all!

Suppose I have some time series data with an uneven sampling frequency in the form:

A = [2008 12 2 9 31 33 1.94 2500; ...

2008 12 2 9 35 18 2 100; ...

2008 12 2 9 35 19 2 100; ...

2008 12 2 9 35 31 1.98 100; ...

2008 12 2 9 38 14 1.94 150; ...

2008 12 2 9 48 49 1.90 500; ...

2008 12 2 9 49 38 1.89 100; ...

2008 12 2 9 49 52 1.91 100; ...

2008 12 2 9 50 8 1.89 100; ...

2008 12 2 9 50 12 1.89 100; ...

2008 12 2 9 50 27 1.88 100]

where effectively,

A = [yyyy mo dd mm ss price vol]

yyyy - year

mo - month

dd - day

mm - minute

ss - second

price - price

vol - volume

I have also created a matrix, say, B such that

B = [2008 12 2 9 30 x1 y1; ...

2008 12 2 9 35 x2 y2; ...

2008 12 2 9 40 x3 y3; ...

2008 12 2 9 45 x4 y4; ...

2008 12 2 9 50 x5 y5; ...

2008 12 2 9 55 x6 y6 ; ...

2008 12 2 9 0 x7 y7 ; ...

2008 12 2 10 5 x8 y8 ; ...

2008 12 2 10 10 x9 y9 ; ...]

Where x_i and y_j are just blanks right now but I’ve showed them here on this forum for clarity.

My goal is to “down sample” my uneven sampled data from matrix A to the evenly sampled matrix B. Specifically, I’m interested in picking the “last” price and the “sum” of the volume. As an illustration, I want to somehow make the records

[9 35 18 2 100],

[9 35 19 2 100],

[9 35 31 1.98 100]

from A such that the corresponding entry in B would select

[9 35 x2 y2]

x2 = last entry = 1.98;

y2 = sum = 100 + 100 + 100 + 100 = 400

That is, all the entries in A right now correspond to the times (in hh:mm:ss) 9:35:18, 9:35:19, 9:34:19 and 9:35:31. Since all of these times fall into the 35-th minute of the 9-th hour (regardless of second), I would like the last price entry of these three to be inserted into the corresponding 35-th minute of the 9-th hour in matrix B; similarly, I would like the sum of these three volumes to be inserted in the same fashion. I would like to add that I would regard a time like 9:35:59 to be regarded to be still in the 35-th minute and note "rounded up" to the 36-th minute.

I think the biggest challenge (at least to a novice like me) is to somehow set the rule such that the hours, minutes and the seconds from A matches up correctly in that of matrix B. Notice that in matrix B I have dropped the seconds column.

I would appreciate any help in doing this! It would be a fantastic and great help! Thank you in advance!

R L

"R L" <rcwlhk@hotmail.com> wrote in message <h441sm$fl4$1@fred.mathworks.com>...

> Hi everybody!

>

> I'm sure there must be a very simple way to solve this problem but I'm still a relative novice to Matlab so I'd appreciate any help on this! Thanks in advance to all!

>

> Suppose I have some time series data with an uneven sampling frequency in the form:

>

> A = [2008 12 2 9 31 33 1.94 2500; ...

> 2008 12 2 9 35 18 2 100; ...

> 2008 12 2 9 35 19 2 100; ...

> 2008 12 2 9 35 31 1.98 100; ...

> 2008 12 2 9 38 14 1.94 150; ...

> 2008 12 2 9 48 49 1.90 500; ...

> 2008 12 2 9 49 38 1.89 100; ...

> 2008 12 2 9 49 52 1.91 100; ...

> 2008 12 2 9 50 8 1.89 100; ...

> 2008 12 2 9 50 12 1.89 100; ...

> 2008 12 2 9 50 27 1.88 100]

>

> where effectively,

> A = [yyyy mo dd mm ss price vol]

>

> yyyy - year

> mo - month

> dd - day

> mm - minute

> ss - second

> price - price

> vol - volume

>

> I have also created a matrix, say, B such that

>

> B = [2008 12 2 9 30 x1 y1; ...

> 2008 12 2 9 35 x2 y2; ...

> 2008 12 2 9 40 x3 y3; ...

> 2008 12 2 9 45 x4 y4; ...

> 2008 12 2 9 50 x5 y5; ...

> 2008 12 2 9 55 x6 y6 ; ...

> 2008 12 2 9 0 x7 y7 ; ...

> 2008 12 2 10 5 x8 y8 ; ...

> 2008 12 2 10 10 x9 y9 ; ...]

>

> Where x_i and y_j are just blanks right now but I’ve showed them here on this forum for clarity.

>

> My goal is to “down sample” my uneven sampled data from matrix A to the evenly sampled matrix B. Specifically, I’m interested in picking the “last” price and the “sum” of the volume. As an illustration, I want to somehow make the records

> [9 35 18 2 100],

> [9 35 19 2 100],

> [9 35 31 1.98 100]

> from A such that the corresponding entry in B would select

>

> [9 35 x2 y2]

> x2 = last entry = 1.98;

> y2 = sum = 100 + 100 + 100 + 100 = 400

>

> That is, all the entries in A right now correspond to the times (in hh:mm:ss) 9:35:18, 9:35:19, 9:34:19 and 9:35:31. Since all of these times fall into the 35-th minute of the 9-th hour (regardless of second), I would like the last price entry of these three to be inserted into the corresponding 35-th minute of the 9-th hour in matrix B; similarly, I would like the sum of these three volumes to be inserted in the same fashion. I would like to add that I would regard a time like 9:35:59 to be regarded to be still in the 35-th minute and note "rounded up" to the 36-th minute.

>

> I think the biggest challenge (at least to a novice like me) is to somehow set the rule such that the hours, minutes and the seconds from A matches up correctly in that of matrix B. Notice that in matrix B I have dropped the seconds column.

>

> I would appreciate any help in doing this! It would be a fantastic and great help! Thank you in advance!

>

> R L

One of the standard ways of tackling this problem is to attempt to interpolate between your samples - cubic splines are often used. Once you have the interpolated waveform you can then provide a virtual uniform sample rate, and then use the Matlab function

help resample --> needs the signal process toolbox I believe

to provide the new rate that you require. This function supplies the all of the anti aliasing filtering you need, if you are downsampling, and is probably a safer way to go rather than simply cherry picking down your interpolated data to form your newly sampled signal.

Hope this helps

Dave Robinson

"Dave Robinson" <dave.robinson@somewhere.biz> wrote in message <h444f8$4pk$1@fred.mathworks.com>...

> "R L" <rcwlhk@hotmail.com> wrote in message <h441sm$fl4$1@fred.mathworks.com>...

> > Hi everybody!

> >

> > I'm sure there must be a very simple way to solve this problem but I'm still a relative novice to Matlab so I'd appreciate any help on this! Thanks in advance to all!

> >

> > Suppose I have some time series data with an uneven sampling frequency in the form:

> >

> > A = [2008 12 2 9 31 33 1.94 2500; ...

> > 2008 12 2 9 35 18 2 100; ...

> > 2008 12 2 9 35 19 2 100; ...

> > 2008 12 2 9 35 31 1.98 100; ...

> > 2008 12 2 9 38 14 1.94 150; ...

> > 2008 12 2 9 48 49 1.90 500; ...

> > 2008 12 2 9 49 38 1.89 100; ...

> > 2008 12 2 9 49 52 1.91 100; ...

> > 2008 12 2 9 50 8 1.89 100; ...

> > 2008 12 2 9 50 12 1.89 100; ...

> > 2008 12 2 9 50 27 1.88 100]

> >

> > where effectively,

> > A = [yyyy mo dd mm ss price vol]

> >

> > yyyy - year

> > mo - month

> > dd - day

> > mm - minute

> > ss - second

> > price - price

> > vol - volume

> >

> > I have also created a matrix, say, B such that

> >

> > B = [2008 12 2 9 30 x1 y1; ...

> > 2008 12 2 9 35 x2 y2; ...

> > 2008 12 2 9 40 x3 y3; ...

> > 2008 12 2 9 45 x4 y4; ...

> > 2008 12 2 9 50 x5 y5; ...

> > 2008 12 2 9 55 x6 y6 ; ...

> > 2008 12 2 9 0 x7 y7 ; ...

> > 2008 12 2 10 5 x8 y8 ; ...

> > 2008 12 2 10 10 x9 y9 ; ...]

> >

> > Where x_i and y_j are just blanks right now but I’ve showed them here on this forum for clarity.

> >

> > My goal is to “down sample” my uneven sampled data from matrix A to the evenly sampled matrix B. Specifically, I’m interested in picking the “last” price and the “sum” of the volume. As an illustration, I want to somehow make the records

> > [9 35 18 2 100],

> > [9 35 19 2 100],

> > [9 35 31 1.98 100]

> > from A such that the corresponding entry in B would select

> >

> > [9 35 x2 y2]

> > x2 = last entry = 1.98;

> > y2 = sum = 100 + 100 + 100 + 100 = 400

> >

> > That is, all the entries in A right now correspond to the times (in hh:mm:ss) 9:35:18, 9:35:19, 9:34:19 and 9:35:31. Since all of these times fall into the 35-th minute of the 9-th hour (regardless of second), I would like the last price entry of these three to be inserted into the corresponding 35-th minute of the 9-th hour in matrix B; similarly, I would like the sum of these three volumes to be inserted in the same fashion. I would like to add that I would regard a time like 9:35:59 to be regarded to be still in the 35-th minute and note "rounded up" to the 36-th minute.

> >

> > I think the biggest challenge (at least to a novice like me) is to somehow set the rule such that the hours, minutes and the seconds from A matches up correctly in that of matrix B. Notice that in matrix B I have dropped the seconds column.

> >

> > I would appreciate any help in doing this! It would be a fantastic and great help! Thank you in advance!

> >

> > R L

>

> One of the standard ways of tackling this problem is to attempt to interpolate between your samples - cubic splines are often used. Once you have the interpolated waveform you can then provide a virtual uniform sample rate, and then use the Matlab function

>

> help resample --> needs the signal process toolbox I believe

>

> to provide the new rate that you require. This function supplies the all of the anti aliasing filtering you need, if you are downsampling, and is probably a safer way to go rather than simply cherry picking down your interpolated data to form your newly sampled signal.

>

> Hope this helps

>

> Dave Robinson

Thanks for the advice Dave! Much appreciated!

However, for the purpose of my project, it is suffice to just "cherry pick" the data points as I had indicated above; in fact, for my purpose, it is much desired over an interpolation technique that is offered by the resample function of Matlab.

Can somebody please help? Thanks again in advance!

You can think of your watch list as threads that you have bookmarked.

You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.

To add items to your watch list, click the "add to watch list" link at the bottom of any page.

To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.

You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.

To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.

To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.

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.

The newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.

Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.

Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.

There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.

**MATLAB Central**

You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.

Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.

**One Account**

Your MATLAB Central account is tied to your MathWorks Account for easy access.

**Use the Email Address of Your Choice**

The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.

**Spam Control**

Most newsgroup spam is filtered out by the MATLAB Central Newsreader.

**Tagging**

Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.

**Watch lists**

Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.

- Use a newsreader through your school, employer, or internet service provider
- Pay for newsgroup access from a commercial provider
- Use Google Groups
- Mathforum.org provides a newsreader with access to the comp.soft sys.matlab newsgroup
- Run your own server. For typical instructions, see: http://www.slyck.com/ng.php?page=2