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

1 次查看(过去 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 个评论
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 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by