What does the varargin function do and what does varargin{:} mean?
조회 수: 170 (최근 30일)
이전 댓글 표시
For example: [varargin{:}] = convertStringsToChars(varargin{:});
댓글 수: 3
Stephen23
2020년 6월 24일
This is incorrect: no arrays are being concatenated.
When used on the LHS it refers to the elements of the cell array, just like on the RHS. The only difference is that values are being assigned to those elements rather than extracted from them. This is explained in the section "Assigning to a Comma-Separated List" here:
채택된 답변
Stephen23
2020년 6월 24일
편집: Stephen23
2022년 2월 23일
"What does the varargin function do..."
varargin is not a function, it is a cell array which contains any number of optional input arguments:
"... and what does varargin{:} mean?"
That syntax creates a comma-separated list from the cell array varargin:
So your example is equivalent to this:
[varargin{1},varargin{2},..,varargin{end}] = convertStringsToChars(varargin{1},varargin{2},..,varargin{end});
댓글 수: 0
추가 답변 (1개)
KSSV
2020년 6월 24일
varargin stands for variable number of arguments. You can input any number of arguments to the function. And these inputs are read by nargin which means the number of inputs.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!