MATLAB: How to create an input loop

elseerrorglobalifinputloopMATLABpromptrange

globloopprompt = 'Input value for Alpha :';
alpha = input(prompt);
if (alpha>=0.01 && alpha<=0.2)
global alpha;
else
error ('Incorrect alpha value');
end
I am new to matlab. Ive created this function and t all works with my corisponding code.
how would i make this code prompt the user to input another value for alpha, if they original enter a value for alpha outside the perameters.
Thank you in advance.

Best Answer

EDITED
Avoid using global , how about the below?:
Save the below as a function with the name inputalpha.m and just call this function in the script.
function alpha = inputalpha
prompt = 'Input value for Alpha :';
alpha = input(prompt);
if (alpha>=0.01 && alpha<=0.2)
alpha=alpha;
else
disp('Incorrect alpha value not within bounds');
prompt = 'Input value for Alpha :';
alpha = input(prompt);
end
end