MATLAB: Check an array of values if within an upper and lower limit

if and else statement checking array of numbers

I am trying to do the same thing as the following example but checking an array of numbers and not just x. However it is not working. can someone help?
x = 10;
minVal = 2;
maxVal = 6;
if (x >= minVal) && (x <= maxVal)
disp('Value within specified range.')
elseif (x > maxVal)
disp('Value exceeds maximum value.')
else
disp('Value is below minimum value.')
end

Best Answer

If you want to operate on arrays you could do it like this:
x = 1:10;
minVal = 2;
maxVal = 6;
x(x(x<=maxVal)>=minVal)
disp('Values within specified range.')