How to check if a user input is between a certain range

6 views (last 30 days)
For a project I am working on I am asked to get a users input and make sure that it is between 0,1. I am not sure the best way to go about this. The variable is z that the user is inputting
  2 Comments
Adam
Adam on 14 Mar 2018
Inputting how? Via command line or in a GUI?
It seems to just be a simple case of using > and < and firing off an appropriate message if it is outside the range though.

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 14 Mar 2018
Edited: James Tursa on 14 Mar 2018
Use an "if test" combined with the results of the expressions z > 0 and z < 1 (or possibley z >= 0 and z <= 1 depending on what is meant by "between" in your problem statement). Look at the doc for "if" to see examples of using an "if test".

Categories

Find more on Startup and Shutdown 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!