MATLAB Answers

Is there a way to export functions using Arguments Validation to older MATLAB versions?

4 views (last 30 days)
Liron Stettiner
Liron Stettiner on 8 Jun 2020
Edited: Liron Stettiner on 8 Jun 2020
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!

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!