Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Ismember/intersect not possible with serial date numbers?
Replies: 7   Last Post: Mar 5, 2013 10:22 PM

 Messages: [ Previous | Next ]
 Derek Goring Posts: 3,922 Registered: 12/7/04
Re: Ismember/intersect not possible with serial date numbers?
Posted: Mar 5, 2013 3:06 PM

On Tuesday, March 5, 2013 11:07:08 AM UTC+13, Vegard wrote:
> Hi,
>
>
>
> I am trying to intersect two arrays containing time records. The first array is a sequence with all the minutes of a year, while the second contains the times of the actual records (a few thousand). Each time record in each array is represented by a (row) date vector with information on the year, month, day, hour and minute of the record, but all seconds are set to zero.
>
>
>
> The following does what I want, but is slow:
>
> [~,iavec,ibvec] = intersect(year_vec(:,1:6),records_vec(:,1:6),'rows','stable');
>
>
>
> To speed it up, I tried to convert all the date vectors to serial date numbers and use the following instead:
>
> [~,ia_serial,ib_serial] = intersect(year_serial(:,1),records_serial(:,1),'stable');
>
>
>
> However, they do not produce the same indices ia_serial/iavec and ib_serial/ibvec...! The same thing happens with ismember. Is this due to limited precision of the date numbers in memory or am I missing something?
>
>
>
> All help greatly appreciated!

The answer is in this FAQ:
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

The way I'd do it is, instead of finding the intersection of floating point numbers which is problematical, convert them to strings using datestr, then intersect will work OK.

Date Subject Author
3/4/13 dpb
3/5/13 dpb
3/5/13 dpb
3/5/13 dpb
3/5/13 Derek Goring