MATLAB: Please advise me on how to improve the efficiency of this code

helpMATLABnewnew to matlabnewbie

As the title says, how can i improve on this on the code on the second line?
try_again = input('Do you want to try again?\nPlease enter yes or no:','s');
while strcmp(try_again,'') == 1 | strcmp(try_again,'yes') ~= 1 | strcmp(try_again,'y') ~= 1 |strcmp(try_again,'no') ~= 1 | strcmp(try_again,'n') ~= 1
try_again = input('Please enter yes or no:','s');
if strcmp(try_again,'yes') | strcmp(try_again,'y')
scriptA
elseif strcmp(try_again,'no') | strcmp(try_again,'n')
break
end
end
Any help or tips would be very greatful, thank you very much

Best Answer

You could use an explicit dialog box to avoid any confusion:
answer = questdlg(...
'Do you want to try again?', ...%question body
'Retry?', ...%box title
'Yes','No', ...%options
'Yes');%default
if strcmp(answer,'Yes')
scriptA
end
If a GUI option is not acceptable you can use something similar to the suggestion by darova:
options={'yes',1;'y',1;'no',0;'n',0};
try_again = input('Do you want to try again?\nPlease enter yes or no:','s');
L=ismember(options(:,1),try_again);
while ~any( L )
try_again = input('Do you want to try again?\nPlease enter yes or no:','s');
L=ismember(options(:,1),try_again);
end
if options{L,2}
scriptA
end