comparing if specific date and time reside in other two cell arrays

조회 수: 4 (최근 30일)
siki
siki 2016년 12월 1일
답변: Peter Perkins 2016년 12월 11일
*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
Jan
Jan 2016년 12월 1일
편집: Jan 2016년 12월 1일
"cot" is not a valied month name. Please post the input data in Matlan syntax, such that it can be used by copy&paste for a suggested solution.
What exactly does "fetch all those elements" mean? What is the wanted output?
siki
siki 2016년 12월 1일
typing mistake it was actually 'Oct' not 'Cot'.... I want to find elapsed and remaining time by calculating (elapse = fetched entry - start point) and (remaining = fetched entry - stop point)

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
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
siki
siki 2016년 12월 1일
편집: siki 2016년 12월 1일
I have applied solution you have given to me. your script only provides total number of matched items, but I want to know exactly match items not total number of elements and want result by calculating matched item-start point and matched item-stop point in other variables.
Jan
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
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.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by