MATLAB: Find range between two array’s indexes

accepted wrong answerarrayMATLABrange

Hello,
I have two arrays of different sizes and I Would like to find certain range between them, where the start index is from one array and ends with another array. For example:
A = [4192 23330 23342 29974 49089 49093 49096 55753 57035 57039]
B = [22780 48556 56522]
The desired output would be
C = [4192 22780; 29974 48556 ; 49096 56522]
Note that A and B can change in size, but array B is always the end point value.
Thanks, Max

Best Answer

Assuming that the rule really should pick the closest values from A that a re less than the values in B:
>> A = [4192 23330 23342 29974 49089 49093 49096 55753 57035 57039];
>> B = [22780 48556 56522];
>>
>> X = A(any(diff(bsxfun(@lt,A(:),B(:).')),2));
>> C = [X(:),B(:)]
C =
4192 22780
29974 48556
55753 56522