MATLAB Answers

Strip duration row with time duration 00:00:00:000

2 views (last 30 days)
Jogger on 19 Dec 2019
Edited: Jogger on 25 Dec 2019
I want to remove all rows expect the last with duration 00:00:00:000
Sample out data


Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 19 Dec 2019
Edited: Adam Danz on 19 Dec 2019
I'm assuming the WeirdDuration data are duration values. This simple solution assumes that you want to eliminate all rows starting at the first row until the last rows that contains a duration of 0.
% T is the table
lastZeroIdx = find(T.WeirdDuration == duration(0,0,0), 1,'last');
T(1:lastZeroIdx-1,:) = []
if WeirdDuration are not duration values, you can easily modifty the line of code above to use datetime values instead. Example: datetime(0,0,0)


Show 3 older comments
Jogger on 20 Dec 2019
Glad to have Guillaume and Adam in mentor roles.
The theory is interesting and Guilaume stated above WeirdDuration belongs to him is right statement and I am not going to remove it ( I like it as well).
I had several files with unusal time stamp format. I have to bring them on same page to view the result's ( data look completly asynchronous in the begining). I don't know what to do with it and how to analyze full set of text result files . Probably one thing was common and it was time factor ( It is WeirdDuration). It has indeed propagated from Guillaume pointers where now I am in a state of achievement ( my target goal to develop a Text Analysis Toolbox ).... By the way I still have one or more file where I need help. So it will continue some more propagation. Don't get surprised
The back ground for this question is below line of code
1. joinedtimetable = outerjoin(joinedtimetable, structtimetable,'Merge',true); % 'LeftKeys','RightKeys'
2. joinedtimetable = synchronize(joinedtimetable, structtimetable, 'union'); %subsequent times, synchronize. Choose whichever method is prefered
If i use synchronize , it will strip few data and missing data from analysis is NOT ok. So I moved to outerjoin and I get full data but with lot of unwanted data ( duration : 00:00:00:000) stuff which increased result size and I want to throw away eventually
Post Fix , now the result look below . Works as expected. Perfect. Many Thanks
Wish you a super morning . Appreciate and thank you once again.
Adam Danz
Adam Danz on 20 Dec 2019
If you used the method in my answer as a fix, just keep in mind that it will eliminate all rows of data from row 1 until the last row of 0s no matter what data are between. If you expect your timestamps to be in ascending order starting with 0s, then this simple method should be OK.
Glad I could help with your weird durations ;)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!