Is it possible to enforce input argument data types in MATLAB?

后端 未结 4 1702
别那么骄傲
别那么骄傲 2021-01-04 03:41

I would like to ensure that the input arguments to a user-defined MATLAB function (contained in an m-file) are of a certain type. I understand that MATLAB automatically assi

4条回答
  •  星月不相逢
    2021-01-04 04:02

    Matlab provides an 'inputParser' which allows to check inputs. Besides this you can use assertions:

    assert(islogical(yes_or_no),'logical input expected')
    

    To ensure the correct number of input arguments, use narginchk.

    btw: Take a look in some Matlab functions like edit integral and check how tmw deals with this.

提交回复
热议问题