Here's an example implementation of linspace
function using nargin
:
main.m200 chars12 lines
In this implementation, we first check the number of input arguments using nargin
. If nargin
equals 3, we call the built-in linspace
with three input arguments, start
, stop
, and num
. If nargin
equals 2, we call linspace
with two input arguments, start
and stop
. If nargin
is neither 3 nor 2, we throw an error message with error
function.
Note that this implementation intentionally avoids using varargin
.
gistlibby LogSnag