how to put a limited value for an input ?

how to put a limited value for an input ? for example from (0 to 100) and if the user enter a value out of this range it will be invalid input ?

 Accepted Answer

test=0
while test==0
a=input('enter 0<a<100')
if a>0 & a<100
test=1
end
end

6 Comments

mohamed
mohamed on 29 Mar 2013
Edited: mohamed on 29 Mar 2013
i want the input to be a matrix all its values don't exceed this range? for example a=[10 20 50 2 0]
test=min(a)>0 & max(a)<100
% if the condition is true test=1, otherwise test=0
i am sorry that i didn't clarify all what i need, i want to make operations on this matrix so i don't want to use "test". the user will enter the matrix and i want to tell him not to enter any value smaller than zero or greater than 100
a=input('enter values between 0 and 100')
this is right, but if i want to send him an error message when he entered the wrong data ?
add this
if or(min(a)<0, max(a)>100)
display('Error, all values of a should be between 0 and 100')

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!