How to have a function have any number of input arguments
2 ビュー (過去 30 日間)
古いコメントを表示
I am trying to make my own function in matlab. I want to make it so it'll run with whatever amount of input arguments. So this is what I have right now essentially:
myfunction(data1)
And my function works for one input argument. But I want to have the option of running multiple input arguments. I want to do this without having to retype the function command over and over again. So basically I want to do:
myfunction(data1)
or
myfunction(data1,data2)
or
myfunction(data1,data2,data3) . . . . etc
Can this be done?
Thanks
0 件のコメント
採用された回答
Sara
2014 年 7 月 10 日
function myfunction(varargin)
if(nargin == 1)
..code if there is only one input
...e.g., x = varargin{1};
else
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!