comparing if specific date and time reside in other two cell arrays
조회 수: 4 (최근 30일)
이전 댓글 표시
*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
답변 (2개)
Jan
2016년 12월 1일
편집: Jan
2016년 12월 1일
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
Jan
2016년 12월 9일
편집: Jan
2016년 12월 9일
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
2016년 12월 11일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!