|
Crypto Logic <crypto@online.de> wrote in message
<fhje4q$cuu$1@online.de>...
> Hi Malcolm,
>
> I'm not sure if this is what I need. The Matlab files that I have can either
> run with or without GUI, in both cases they are functions that can have
> vars passed over to them. So even though Your trick would help me to see
> whether it is a function or a script, it can happen that:
>
> - my file is a function that does not need any vars passed over to it,
> - my file still does not yet know if it should run automatically or open its
> GUI.
>
> Thx for Your help anyway,
> Crypto.
>
> Malcolm Lidierth wrote:
>
> > Will this do?
> >
> > function MyFunc(varargin)
> >
> > if nargin==0
> > .
> > .
> > else
> > .
> > .
> > end
> >
> > return
> > end
>
A trick that I use sometimes is to add a last argument to the function, which
does not need to be specified when called from the command line, but that
you can use when calling the function from your gui callback.
For example, assuming you your function has normally two arguments:
function MyFunc(in1, in2, varargin)
if nargin > 2
.
else
.
end
(If your function already has a variable number of inputs, try checking the
class of the last varargin... for example, pass an additional logical argument if
you know that normally they are all numerical)
hth
Lorenzo
|