Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
*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 Commenti
Jan
Jan il 1 Dic 2016
Modificato: Jan il 1 Dic 2016
"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 il 1 Dic 2016
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)

Accedi per commentare.

Risposte (2)

Jan
Jan il 1 Dic 2016
Modificato: Jan il 1 Dic 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 Commenti
siki
siki il 1 Dic 2016
Modificato: siki il 1 Dic 2016
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 il 9 Dic 2016
Modificato: Jan il 9 Dic 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)"?

Accedi per commentare.


Peter Perkins
Peter Perkins il 11 Dic 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.

Community Treasure Hunt

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

Start Hunting!

Translated by