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

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

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.
using a z = input('Please input....: ')

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".

Products

Asked:

on 14 Mar 2018

Edited:

on 14 Mar 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!