"If x is between v(h) and v(h+1)", without knowing which of v(h) or v(h+1) is bigger
2 views (last 30 days)
Show older comments
I want to write an if statement with the variable, x, between two values. However, since it is referencing from an array, there is no guarantee which value will be larger and which will be smaller, therefore I cannot use greater equal or lesser equal statement. So if I want to write "If x is between v(h) and v(h+1)", with no clue of which one will be larger, how should I phrase my code?
0 Comments
Accepted Answer
Image Analyst
on 13 May 2014
if x > min([v(h), v(h+1)]) && x < max([v(h), v(h+1)])
% It's in range.....do stuff....
0 Comments
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!