From: Luna Moon on 4 Feb 2010 09:51 function result=mytryfunc(x, y, z) if isundefined(y) do something... end; if isundefined(z) do something... end; But there is no such command called "isundefined" in Matlab... So I want to write my own "isundefined" function to detect undefined arguments... How to do that? Thanks a lot!
From: Jos (10584) on 4 Feb 2010 10:07 Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <8f077866-ef54-4f60-b327-af754c70d39e(a)v5g2000vbb.googlegroups.com>... > function result=mytryfunc(x, y, z) > > if isundefined(y) > do something... > end; > > if isundefined(z) > do something... > end; > > But there is no such command called "isundefined" in Matlab... > > So I want to write my own "isundefined" function to detect undefined > arguments... > > How to do that? > > Thanks a lot! How would you define "undefined" here? Is someone is calling your function like this mytryfunc(1) do you assume, as most functions do, that Y and Z are missing? What about the call mytryfunc([],2,3) Take a look at NARGIN and ISEMPTY, and use a couple of IF's to set the 'undefined' variables to a default value. if nargin<3 || isempty(Z), Z = .. end if nargin < 2 || isempty(Y), % note that Z has been set to default already Y = end hth Jos
From: Walter Roberson on 4 Feb 2010 10:43 Luna Moon wrote: > function result=mytryfunc(x, y, z) > > if isundefined(y) > do something... > end; > > if isundefined(z) > do something... > end; > > But there is no such command called "isundefined" in Matlab... > > So I want to write my own "isundefined" function to detect undefined > arguments... > > How to do that? if ~exist('y','var')
|
Pages: 1 Prev: Legend for bar Next: neat way to rotate elements in an array ? |