To write your own version of linspace()
function in MATLAB with nargin
checks, you can use the following code:
main.m1933 chars62 lines
In the above function, the input arguments are checked using nargin
and switch
statements. The default number of points and the default class of the output are defined as n
and double
, respectively. If the number of input arguments is 2, the default number of points is used. If the number of input arguments is 3, the third argument is assumed to be the number of points. If the number of input arguments is 4, the third argument is assumed to be the number of points and the fourth argument is assumed to be the output class. If the input values are invalid, an error is thrown.
The linspace()
function is then called using the start value, stop value, and number of points. If the output class is specified, the output is cast to that class. Finally, the output vector is returned.
gistlibby LogSnag