I basically ask a user to enter Yes or No in a message box. How do I either convert their answer into a value of 1 for Yes, yes or Y? Thanks
MATLAB: User Input
MATLABmessage boxuser input
MATLABmessage boxuser input
YesNo = input(prompt2,'s')
function i = getnum(prompt, default)% GETNUM Read a numerical value from the keyboard
%
% I = GETNUM(PROMPT) prints the string PROMPT and waits for the user
% to type a number followed by return. Checks that the input does
% actually represent a scalar and prompts again if necessary.
% Returns the number.
%% I = GETNUM(PROMPT, DEFAULT) does the same except that the number
% DEFAULT is printed after the prompt, and is returned if the user
% just presses return. Setting DEFAULT to [] is the same as omitting
% it.
% David Young, March 2002
if nargin < 2 default = [];endif isempty(default) str = prompt;else if ~checknum(default) error('Expecting numerical default argument'); end; str = [prompt, ' [', num2str(default), '] '];end;i = [];while isempty(i) i = input(str, 's'); if isempty(i) && ~isempty(default) i = default; else i = str2num(i); %#ok<ST2NM>
if ~checknum(i) disp('A single number expected'); i = []; end endendendfunction i = checknum(x)% Checks whether its argument is a single number
i = isnumeric(x) && isscalar(x);end
Best Answer