Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,892
Registered: 12/7/04
Re: Ismember/intersect not possible with serial date numbers?
Posted: Mar 5, 2013 3:06 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.