Effacer les filtres
Effacer les filtres

How to define a function that can have multiple variables.

3 vues (au cours des 30 derniers jours)
C Zeng
C Zeng le 11 Juin 2012
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.

Réponse acceptée

the cyclist
the cyclist le 11 Juin 2012
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 commentaires
the cyclist
the cyclist le 12 Juin 2012
I edited my reply to include a web page that has an example.
C Zeng
C Zeng le 12 Juin 2012
thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by