I need to declare a function that has 32 arguments, so it would be handy to put an unique argument: an array of 32 elements.
I don’t find the syntax to do that, I’ve tried everythinh like:
function x=myfunction(str(32)) (etc…)
But without success.
I need to declare a function that has 32 arguments, so it would be
Share
Unlike other languages, MATLAB can accept matrices as a single argument; so you could just check that the input argument is a vector of length 32:
If it’s a variable number of arguments, check out
varargin:But for 32 arguments, consider using an input structure:
Supply arguments in the structure, then pass the structure:
Then in the function, you could either call
argStruct.arg1, etc, directly; or unpack it into 32 different variables inside the function. I would give the fields descriptive names so you don’t refer to them asarg1, etc inside your function. For that many input arguments, people using the function probably won’t remember the order in which your function requires them to pass inputs to. Doing it with a struct lets users pass in arguments without needing to think about what order those inputs are defined.