- https://www.mathworks.com/help/matlab/ref/inputparser.html
- https://www.mathworks.com/help/matlab/ref/varargin.html
HOW TO CHECK THE PARAMETERS RECEIVED IN THE FUNCTION CALL?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
federica pasquali
el 2 de Ag. de 2018
Comentada: OCDER
el 9 de Ag. de 2018
dear all,
this is my function : function [] = print( value1 , value2, value3 ,value4,value5,value6,value7,value8)
value1 and value 2 are REQUIRED the others are OPTIONAL . I need to know how to check which parameters i've received and their value , because some of them could be numbers , characters . and i don't know how to do that. thanks
0 comentarios
Respuesta aceptada
OCDER
el 2 de Ag. de 2018
I think input parser + varargin is what you need here.
Example:
%Changed the name "print" to "print2" to prevent overriding matlab built-in "print" function
function [] = print2(varargin)
P = inputParser;
addRequired(P, 'value1', @ischar);
addRequired(P, 'value2', @isnumeric);
addOptional(P, 'value3', [], @(x) ischar(x) || isnumeric(x));
parse(P, varargin{:});
P = P.Results; %Just so you can refer to value1 as P.value1, not P.Results.value1 (downside to inputParser)
%To get value1, use P.value1
Alternatively, you'll have to make your own input-parsing function
10 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Argument Definitions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!