MATLAB: Compare matrix column-wise with vector

arrayfuncolumnwisematrix manipulationvector manipulation

Dear all,
I have an mxn matrix and a 1xn vector I want to compare each ith column of the matrix with the ith value of the vector. The result should be an mxn logical matrix to be used
Example:
minVec = [ 0 2 0];
maxVec = [10 10 9];
mat = [-1 2 5;
9 15 3];
I would like to calculate the following, but without a for-loop…
mask(:,i) = mat(:,i)<minVec(i) | mat(:,i)>maxVec(i);
mask = [ 1 0 0;
0 1 0]
I guess there must be some solution using arrayfun, perhaps?
Any help is greatly appreciated!
Thank you very much, Philip

Best Answer

mask=bsxfun(@lt,mat,minVec)| bsxfun(@gt,mat,maxVec)