How can I get successive difference and later add all the difference?

735954.715277778 735954.716412037 735954.717766204 735954.717824074 735954.717916667 735954.863611111 735955.043206019 735955.043773148 735969.629212963 735969.629421296 735969.634259259 735969.743506944 735969.744884259 735969.745000000 735969.745590278 735969.745949074 735969.749062500 735969.818958333 735969.826678241 735969.826793982......
These are the timestamps. I want difference between successive timestamps like (2-1) second minus first, fourth minus third (4-3) and so on and add the difference.I want final result in minutes. Like (2-1)+(4-3)+(6-5)...... Any Suggestions on how to solve it?

 Accepted Answer

x = [735954.715277778 735954.716412037 735954.717766204 735954.717824074 735954.717916667 735954.863611111 735955.043206019 735955.043773148];
x = diff(x);
d = sum(x(1:2:end));
[~,~,~,h, mn, s] = datevec(datetime(d,'ConvertFrom','datenum','Format','hh:mm:ss'));
dmin = h*60+mn+s/60;
dmin =
212.333330729167

6 Comments

Nope did not get the right sum. Also I am using MATLAB 2013a so datetime did not work for me. I used datestr but keeping other things same I got different answer. I am doing it for following timestamps
735954.715277778 735954.716412037 735954.717766204 735954.717824074 735954.717916667 735954.863611111 735955.043206019 735955.043773148
Got 473.But answer should be 212. Any thoughts?
How do you know that the correct answer is 212? Converting:
x = [735954.715277778 735954.716412037 735954.717766204 735954.717824074 735954.717916667 735954.863611111 735955.043206019 735955.043773148];
dates = datetime(x,'ConvertFrom','datenum','Format','hh:mm:ss')
results in:
dates =
05:10:00 05:11:38 05:13:35 05:13:39 05:13:48 08:43:35 01:02:13
01:03:01
473 looks reasonable to me
I have a csv file with timestamp in yyyy-mm-dd I calculated manually to cross verify and 212. I cross verified 3 times.
you got the timestamps right now what i want to do is (2-1)+(4-3)+(6-5)+(8-7)
I've edited my answer.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Parallel Server in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!