How to define a function that can have multiple variables.

For example f(x,y,z) or f(x,y), z is optional. If I list three variables then system uses f(x,y,z), if only 2 variables uses f(x,y).
I know how to use it by nargin function, is there better way to do so?
Thanks.

 Respuesta aceptada

When you say you know how to do it by nargin, does that mean you are also familiar with varargin? That sounds like what you want.
>> doc varargin
There is an example on this page:

3 comentarios

C Zeng
C Zeng el 11 de Jun. de 2012
Hi, thanks. Yes, I know how to do it by nargin, by writing a if nargin<3 command.
Could you write an example by using varragin?
Thank you!
I edited my reply to include a web page that has an example.
C Zeng
C Zeng el 12 de Jun. de 2012
thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Types en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Jun. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by