How to have a function have any number of input arguments

조회 수: 2 (최근 30일)
Hail
Hail 2014년 7월 10일
댓글: Hail 2014년 7월 10일
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

채택된 답변

Sara
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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by