How do I write a function that behaves differently according to the number of input arguments?
4 ビュー (過去 30 日間)
古いコメントを表示
First, is it possible to write a function that variably accepts some number of arguments? (It should be possible since to create objects, you often call functions and specify a variable number of properties that you wish to initialize).
Secondly, how do you count the number of arguments? Are arguments received as strings?
0 件のコメント
回答 (2 件)
Thorsten
2015 年 9 月 10 日
編集済み: Thorsten
2015 年 9 月 10 日
Use varargin as the parameter of your function that collects all arguments as elements of a cell array.
function myplot(varargin)
%number of arguments
numel(varargin)
% first argument
varargin{1}
You can use other arguments in front of varargin.
function myplot(x, y, varargin)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Argument Definitions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!