Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: subtracting time difference

Subject: subtracting time difference

From: jason

Date: 11 Aug, 2007 05:23:10

Message: 1 of 3

hi

i have some data that i am recording the time that it enters
the serial port. it is currently been written to a file, but
i would also like to find the difference in time between the
sequences of data.

the data is stored in the file like this:

4f 09.22.569
63 09.22.588
67 09.22.613

with the first part being hex data and the second part is
the time stamp using datestr(now('MM.SS.FFF'));

how do i set it up so that it finds the difference in time
between 09.22.588 and 09.22.613? it cant be changed using
datenum because datenum doesnt recognise SS.FFF.

thanks in advance
jase

Subject: Re: subtracting time difference

From: dpb

Date: 11 Aug, 2007 13:37:12

Message: 2 of 3

jason wrote:
> hi
>
> i have some data that i am recording the time that it enters
> the serial port. it is currently been written to a file, but
> i would also like to find the difference in time between the
> sequences of data.
>
> the data is stored in the file like this:
>
> 4f 09.22.569
> 63 09.22.588
> 67 09.22.613
>
> with the first part being hex data and the second part is
> the time stamp using datestr(now('MM.SS.FFF'));
>
> how do i set it up so that it finds the difference in time
> between 09.22.588 and 09.22.613? it cant be changed using
> datenum because datenum doesnt recognise SS.FFF.

Write your own function to handle the format you have.

All you need basically is 1000*(MM*60 + SS) + FFF for each numbers
(scaling to integers) for each number and then take the difference and
reverse the scaling.

Or, if not concerned about the minor amount of floating point roundoff
you could forget the scaling by 1000

timestampserial == MM*60 + SS.FFF

--

Subject: Re: subtracting time difference

From: us

Date: 11 Aug, 2007 13:54:40

Message: 3 of 3

jason:
<SNIP may have an older ML version...

> datenum doesnt recognise SS.FFF.

well, here it does

<pre class="code">

% the data
     t1=datenum('09.12.111','MM.SS.FFF');
     t2=datenum('09.12.222','MM.SS.FFF');
     td=t2-t1
% the check
     datestr(t1,'MM.SS.FFF')
     datestr(td,'SS.FFF')

</pre>

us

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics