you can use bsxfun
to compare A
to start time and end time in B
:
startTime = vertcat( B{:,1} ); % assuming B is 6x3 cell array
endTime = vertcat( B{:,2} );
sel = bsxfun( @ge, A', startTime ) & bsxfun( @le, A', endTime ); % check valid interval
[valid inIdx] = max( sel, [], 1 );
valid
is either 1 (for elements in A
falling inside one of the intervals in B
), or 0. For those elements of A
for which valid
is 1, the corresponding value of inIdx
will give you the interval index (1 to 6).