No Switch statement is needed. This practice is to get the input and put it in the right format.
help input
INPUT Prompt for user input.
RESULT = INPUT(PROMPT) displays the PROMPT string on the screen, waits
for input from the keyboard, evaluates any expressions in the input,
and returns the value in RESULT. To evaluate expressions, INPUT accesses
variables in the current workspace. If you press the return key without
entering anything, INPUT returns an empty matrix.
STR = INPUT(PROMPT,'s') returns the entered text without evaluating expressions.
To create a prompt that spans several lines, use '\n' to indicate each
new line. To include a backslash ('\') in the prompt, use '\\'.
Example:
reply = input('Do you want more? Y/N [Y]:','s');
if isempty(reply)
reply = 'Y';
end
See also KEYBOARD.
Documentation for input
doc input
help sprintf
sprintf - Format data into string or character vector
This MATLAB function formats the data in arrays A1,...,An using the
formatting operators specified by formatSpec and returns the resulting
text in str.
Syntax
str = sprintf(formatSpec,A1,...,An)
[str,errmsg] = sprintf(formatSpec,A1,...,An)
str = sprintf(literalText)
Input Arguments
formatSpec - Format of output fields
formatting operators
A1,...,An - Numeric, character, or string arrays
arrays
literalText - Input text without formatting operators
character vector | string scalar
Output Arguments
str - Formatted text
character vector | string scalar
errmsg - Error message
character vector
Examples
openExample('matlab/FloatingPointFormatsExample')
openExample('matlab/LiteralTextandArrayInputsExample')
openExample('matlab/SpecifyFormattedTextAsStringArrayExample')
openExample('matlab/IntegerFormatwithFloatingPointInputsExample')
openExample('matlab/SpecifyFieldWidthofaPrintedValueExample')
openExample('matlab/ReorderInputsUsingPositionIdentifiernExample')
openExample('matlab/CreateaStringfromValuesinCellArrayExample')
See also char, fprintf, int2str, num2str, sscanf, fscanf, compose,
string
Introduced in MATLAB before R2006a
Documentation for sprintf
doc sprintf
Other uses of sprintf
codistributed/sprintf
dlarray/sprintf
gpuArray/sprintf
matlab.automation.internal.diagnostics.FormattableString/sprintf