Check an array of values if within an upper and lower limit
Show older comments
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
Accepted Answer
More Answers (1)
KSSV
on 15 Oct 2018
minVal = 2;
maxVal = 6;
if any(x >= minVal) && any(x <= maxVal)
disp('Value within specified range.')
elseif any(x > maxVal)
disp('Value exceeds maximum value.')
else
disp('Value is below minimum value.')
end
3 Comments
Ayman Fathy
on 15 Oct 2018
Edited: Ayman Fathy
on 15 Oct 2018
Ayman Fathy
on 15 Oct 2018
Ayman Fathy
on 15 Oct 2018
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!