Can I provide multiple function definitions for different input arguments?

9 visualizaciones (últimos 30 días)
Marek Petters
Marek Petters el 13 de Jun. de 2019
Comentada: Adam el 13 de Jun. de 2019
Hello
Is it possible to provide multiple function definitions? Something like in the official documentation, e.g.:
X = rand(n)
X = rand(sz1,...,szN)
X = rand(sz)
X = rand(___,typename)
X = rand(___,'like',p)
I would like to use it for my self-defined class, like:
T = tensor(X)
T = tensor(v1,...,vn)
Where X is a cell array and v's are arrays.
  1 comentario
Adam
Adam el 13 de Jun. de 2019
You can only do that using
doc varargin
followed by a load of lines of big ugly code handling all the various different cases you support. Unfortunately there is no easy way of function overloading like in some other languages.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by