Is there a way to export functions using Arguments Validation to older MATLAB versions?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Greetings,
In version R2020a, MATLAB introduced Function Argument Validation, which allows the coder to pre-define the properties of the input arguments to their function, such as size, class and other limitations, and even set a default value.
The syntax is as follows:
function example(a, b)
arguments
a (1,:) {mustBeNumeric}
b unit32 {mustBeNonNegative} = 3
end
% ...
end
I wanted to find out whether MATLAB has created an option to automatically downgrade those R2020a-syntax functions for campatibility in lower versions, so that the code will look something like:
function example(a, varargin)
if ~isnumeric(a)
error
elseif ~isvector(a)
error
elseif ~isrow(a)
a = a';
end
switch nargin
case 1
b = uint32(3);
case 2
b = unit32(varargin{1});
if b < 0
error
end
otherwise
error
end
% ...
end
Thanks in advance!
0 comentarios
Respuestas (0)
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!