comparing if specific date and time reside in other two cell arrays
3 views (last 30 days)
Show older comments
*loop entry(increased by 1 mint)* *Start time* *End time*
'01-Oct-2011 11:12:00' '01-Oct-2011 11:13:00' '01-Oct-2011 11:13:50'
'01-Oct-2011 11:13:00' '01-Oct-2011 11:13:05' '01-Oct-2011 11:14:05'
'01-Oct-2011 11:14:00' '01-cot-2011 11:14:00' '01-cot-2011 11:14:30'
'01-Oct-2011 11:15:00' '01-Oct-2011 11:15:00' '01-Oct-2011 11:16:00'
I want to check first element in loop column(using loop) and compare it with all elements in start time column and end time column and fetch all those elements which are according to condition (e.g. if (01-Oct-2011 11:12:00 > start time and < stoptime) and assign all fetched elements to new variable. Kindly help me to write its script. After checking loop must be incremented and next time i.e. 01-Oct-2011 11:13:00 must be checked in all elements and so on.
2 Comments
Answers (2)
Jan
on 1 Dec 2016
Edited: Jan
on 1 Dec 2016
data = {'01-Oct-2011 11:12:00', '01-Oct-2011 11:13:00', '01-Oct-2011 11:13:50'; ...
'01-Oct-2011 11:13:00', '01-Oct-2011 11:13:05', '01-Oct-2011 11:14:05'; ...
'01-Oct-2011 11:14:00', '01-Oct-2011 11:14:00', '01-Oct-2011 11:14:30'; ...
'01-Oct-2011 11:15:00', '01-Oct-2011 11:15:00', '01-Oct-2011 11:16:00'};
d = reshape(datenum(data(:)), [], 3);
match = cell(1, size(d, 1));
for iRow = 1:size(d, 1)
ad = d(iRow, 1);
match{iRow} = find(ad >= d(:, 2) & ad <= d(:, 3));
end
2 Comments
Jan
on 9 Dec 2016
Edited: Jan
on 9 Dec 2016
My script does not reply the total number, but the indices of the matching items. Using this you should be able to find the start and end positions by your own: They are the first and last element in match.
It is not clear what you actually want: "want to know exactly match items" or "(elapse = fetched entry - start point) and (remaining = fetched entry - stop point)"?
Peter Perkins
on 11 Dec 2016
siki, I think you want to look into using a table, and the various join functions that tables provide. In R2016b, you might even want to look into using a timetable.
Hope this helps.
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!