Reputation: 1501
Is it possible in Matlab to say what the function expects? something like this:
function functionA( obj, uint8(param) )
Here I am saying that the function expects one parameter of type uint8.
Upvotes: 1
Views: 69
Reputation: 329
To complement Rody's answer, there are four ways that you can do this:
validateattributes
function. See here. This is a very good balance between simplicity and utility. It allows you to check for a number of properties in an argument (and generally, any variable at any part of code)inputParser
class. See here. This is the most powerful method of parsing inputs, but may be overkill. Also, the cost of creating an inputParser
object means that it may not be a good idea for functions that are called repeatedly. Nevertheless, it's very good for the public API.Upvotes: 2
Reputation: 38032
Not on the function signature. Typically, you do this via an assert block:
function (obj, param)
assert(isa(param, 'uint8'),...
[mfilename ':invalid_datatype'],...
'Parameter ''param'' must be of class ''uint8''; received ''%s''.',...
class(param));
Upvotes: 6