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: time rounding issues
Replies: 4   Last Post: Aug 20, 2014 4:51 PM

Advanced Search

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

Posts: 1,986
Registered: 12/6/04
Re: time rounding issues
Posted: Aug 20, 2014 4:51 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Travis " <sinusoid2@hotmail.com> wrote in message <lt2u7a$npt$1@newscl01ah.mathworks.com>...
> "someone" wrote in message <lt2q5u$cqd$1@newscl01ah.mathworks.com>...
> > "Travis " <sinusoid2@hotmail.com> wrote in message <lt2n4e$3vv$1@newscl01ah.mathworks.com>...
> > > I have a large amount of data that is timestamped by the instruments recording it. When processing the data I need a complete time series, but there are times when there are gaps in the record that I need to fill. I have converted the timestring to MATLAB time and created another full time variable using...
> > >
> > > time = t(1):1/48:t(end); %half hour data intervals
> > >
> > > When I use the intersect command though I do not get the desired result; not all the times are the same (even though when I put them back to datestrings they are identical).
> > >
> > > I set up a quick check...
> > >
> > > a(:,1) = 1:1/48:100;
> > > b = 1;
> > > for i = 2:4753; %length of a
> > > b = [b;addtodate(b(i-1),30,'minute')];
> > > end
> > >
> > > c = find(a ~= b); %3168 results.
> > >
> > > Is this a rounding issue with the 1/48? Is there a way to do this without using a for-loop and the addtodate command (I have seen the code slow down a lot when working with larger datasets)?

> >
> > The MATLAB FAQ addresses this issue and provides a workaround:
> >
> > <<http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F>>

>
> That was a good read thank you. So using that new information is there a way to go about using the intersect command with two datasets that are not the same size? I have tried forcing rounding x = round(x*10000)/10000 and it seems to help in most cases, yet not in all.


See dpb's response above for a better workaround.

But to answer your question, you still have the same floating point problems (as you found out) using the round function (the way you are using it). This doesn't simply truncate the number to a certain decimal place as you might think it would. MATLAB still uses the full floating-point representation for the number. Look at the "rounded" numbers with the format long option and you will see it is not exactly what you would expect.



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.