Create an inputParser object and add a required input named myinput to the input scheme.
p = inputParser;
argName = 'myinput';
addRequired(p,argName)
Call the parse function with the input value 7, and display the results.
parse(p,7)
p.Results
ans = struct with fields:
myinput: 7
Create an input parser scheme that checks that a required input is a
nonnegative, numeric scalar. The syntax @(x) creates a handle to an
anonymous function with one input.
The value of 'num' is invalid. It must satisfy the function: @(x)(x>0)&&isnumeric(x)&&isscalar(x).
Create an inputParser object and define a validation
function using validateattributes. The validation
function tests that a required input is numeric, positive, and even.
Parse an input character vector. Parse fails because the input is
invalid.
parse(p,'hello')
The value of 'evenPosNum' is invalid. Expected input to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
Instead its type was char.
Parse an odd number. Parse fails because the input is invalid.
parse(p,13)
The value of 'evenPosNum' is invalid. Expected input to be even.
Input parser scheme, specified as an inputParser object.
Name of the input argument, specified as a character vector or string scalar.
Example: 'firstName'
Example: 'address'
Data Types: char | string
Function to validate an argument, specified as a function handle.
The function handle must be associated with a function that returns true or false, or passes a test, or throws an error. Both types of functions must accept a single input argument.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.