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 ?

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 29 Mar 2013
test=0
while test==0
a=input('enter 0<a<100')
if a>0 & a<100
test=1
end
end

6 commentaires

mohamed
mohamed le 29 Mar 2013
Modifié(e) : mohamed le 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
mohamed
mohamed le 29 Mar 2013
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')
mohamed
mohamed le 29 Mar 2013
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')

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Performance and Memory dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by