Q:

How to compare two vectors with different dimensions to get logical array?

I have two vectors with different dimensions. To make it simple,lets say
A = rand(30, 1);
B = rand(10, 2);

Basically, I want this: if A(i,1)<=B(i,1) & A(i,1)>=B(i,2) is true,then do sth. i tried to use for statement such as for i=size(A),obviously, theres problem because of the two dimensions. If anybody knows how to solve this problem, please let me know.

A:

You can do the following
%# find out which array is longer
lenA = size(A,1);
lenB = size(B,1);

minLength = min(lenA,lenB);

%# do vectorized comparison
trueOrFales = all(A(1:minLength)<=B(1:minLength,1)) && ...
    all(A(1:minLength)>=B(1:minLength,2))

