I am writing a script add reverb to an input file and have it so that the user can input the reverb time and amount of the direct sound they want mixed in. I've been trying to write a function to check the user input but have been having errors with the console getting stuck in the else statement no matter what input I have. This is the code for the function:
function ds = InputCheck(prompt1, prompt2)instr = input(prompt1); % asks user for an input
instr = str2double(instr);while isnumeric(instr) == 1 if (instr > 0) && (instr < 1) % limits for the input value
ds = instr; % outputs the value
break else instr = input(prompt2); instr = str2double(instr); endend
And I have been calling it with this:
ds = InputCheck('Enter how much direct sound to mix in: ','Enter a number between 0 and 1: ');
This is what I get from the console:
>> ProcessingCombScriptEnter how much direct sound to mix in: 0.1Enter a number between 0 and 1: 0.2Enter a number between 0 and 1: 0.3Enter a number between 0 and 1: 0.4Enter a number between 0 and 1: 1Enter a number between 0 and 1: 1.5Enter a number between 0 and 1: -1
As you can see no matter what I enter I get the second prompt message. I know I've probably made a mess of this but any help and improvements would be greatly appreciated.
Best Answer