I wanna define function which has flexible number of argument.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dong-Gyu Jang
am 26 Dez. 2014
Kommentiert: Dong-Gyu Jang
am 30 Dez. 2014
Hello and happy new year!
Now I'm considering to define function which has flexible arguments.
For example, let's have function F which full argument number is 3 such as F(a,b,c)
If b is 0, user don't need to assign c thus F(a,b) is enough. Otherwise full argument assignment is required.
Can I make this kind of flexible function?
0 Kommentare
Akzeptierte Antwort
Shoaibur Rahman
am 26 Dez. 2014
Bearbeitet: Shoaibur Rahman
am 26 Dez. 2014
function out = F(varargin)
% do stuffs
% y = varargin{1}+varargin{2}
% out = y+1; etc.
For flexible number of outputs:
function varargout = F(varargin)
% do stuffs
% varargout{1} = varargin{1}-varargin{2}
% etc.
3 Kommentare
Shoaibur Rahman
am 29 Dez. 2014
This should work in this way. Anyway, it would be better to see the part of your code and the errors generated by the code.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!