I'm writing a function in Matlab that prompts the user to select an Instrument (.wav file) to be read in using the wavread
function.
I'm trying to include some sort of error handling/deal with incorrect inputs from the user.
So far my function looks like this:
prompt = 'Select Instrument, Piano: [P], Fork: [F], Violin: [V], Gameboy: [G]';
str = input(prompt,'s');
if isempty(str)
str = 't';
end
while(str ~= 'P') || (str ~= 'F') || (str ~= 'V') || (str ~= 'G')
prompt = 'Invalid Selection! Choose, Piano: [P], Fork: [F], Violin: [V], Gameboy: [G]';
str = input(prompt,'s');
if isempty(str)
str = 't';
elseif (str == 'P') || (str == 'F') || (str == 'V') || (str == 'G')
break
end
end
If prompted during the while loop, it successfully prompts the user and reads in the .wav
, but if the user presses P
,F
,V
, or G
on the first prompt, the while loop is still used and "Invalid Sel... "
is still displayed...
I'm not sure how I should be implementing this....