Can I provide multiple function definitions for different input arguments?

조회 수: 2 (최근 30일)
Marek Petters
Marek Petters 2019년 6월 13일
댓글: Adam 2019년 6월 13일
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
Adam
Adam 2019년 6월 13일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by