Thread Subject: GUI vs. script

Subject: GUI vs. script

From: Crypto Logic

Date: 15 Nov, 2007 06:46:33

Message: 1 of 5

Hi,

I have written a Matlab-function that is intended to be run either using the
Matlab-prompt or using it as a callback for another function, in this case
it displays a GUI.

Because the GUI of the function cannot be used in "script-mode" (the
function is supposed to run automatically and perform several calculations
on measurement data) the GUI has to be disabled in "script-mode".

What can I do to find out in the function whether it was run via
Matlab-prompt or as a callback etc., so that I can tell the function to use
default values for variables that I would enter using the GUI otherwise?

Thx for any hint here,
Crypto.

Subject: GUI vs. script

From: Malcolm Lidierth

Date: 15 Nov, 2007 11:44:24

Message: 2 of 5

Will this do?

function MyFunc(varargin)

if nargin==0
.
.
else
.
.
end

return
end

Subject: GUI vs. script

From: Crypto Logic

Date: 16 Nov, 2007 06:42:34

Message: 3 of 5

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

Subject: GUI vs. script

From: Lorenzo

Date: 17 Nov, 2007 21:03:14

Message: 4 of 5

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

Subject: GUI vs. script

From: Bruno Luong

Date: 17 Nov, 2007 22:45:46

Message: 5 of 5

Crypo, you could pass extra input parameter solely for the
purpose of knowing who is calling.

But if you insist on "dont't do it myself", then try this

function myprocess(...)

[st]=dbstack;
if length(st)==1
    caller='base';
    ...
else
    caller='function'; % open gui
    ...
end

Bruno

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com