f



global variables in Matlab GUI

Where can I define global variables in Matlab ( GUI application) ?  I
mean that I would like to have
variable which is seen inside every function(
Listbox_callback,pushbutton_Callback etc...)

In other languages (Delphi,Visual C) there are  places where global
variables are put and can be used by the whole application, but I have
no idea how it is in Matlab. I'll be grateful for advice.

Regards, Piotr W.

0
amapola8 (11)
1/24/2007 6:51:50 PM
comp.soft-sys.matlab 211266 articles. 17 followers. lunamoonmoon (258) is leader. Post Follow

1 Replies
352 Views

Similar Articles

[PageSpeed] 34

On Wed, 24 Jan 2007 10:51:50 -0800, rohan wrote:

> Where can I define global variables in Matlab ( GUI application) ?  I
> mean that I would like to have
> variable which is seen inside every function(
> Listbox_callback,pushbutton_Callback etc...)
> 
> In other languages (Delphi,Visual C) there are  places where global
> variables are put and can be used by the whole application, but I have
> no idea how it is in Matlab. I'll be grateful for advice.
> 
> Regards, Piotr W.

Don't use global variables for this. Either attach your variables to the
handles-structure ( it's passed to your functions anyway). Then use
guidata to store the handles-structure:

handles.myVar
guidata(handles)

% now the variable handles.myVar is available to any function that you
pass handles into.

Another option is to use setappdata and getappdata. It is my strong belief
that both methods presented above are better than using global variables.
If you still decide to use global variables, then the only trick is to
define the variables as gloabal in any function where you wish to use the
variable.

/PB
0
PB
1/24/2007 7:01:34 PM
Reply: