f



How can i define global variable in matlab gui?

I'm an old C# user and new matlab gui user.I can define a global variable easily in C# which can be recognized by all program not one function.
I have tried some step for this operation;
1-I have defined the variable;
global x;
x=5;
2-Then I wrote these code under; 
                 "function varargout = filename(varargin)" 
which is located at top.It doesnt work.I couldn't use variable under other functions.
3-Then I have tried to write this code under;
                "function filename_OpeningFcn(hObject, eventdata, handles, varargin)"
But It didn't work again.
4-Then I have tried to write this code under;
                "function varargout = MH_OutputFcn(hObject, eventdata, handles)"
But It didn't work again and again.

How can I fix this problem?Is there anyway for Matlab Gui?
0
dfgdg
7/30/2010 6:23:07 AM
comp.soft-sys.matlab 211266 articles. 17 followers. lunamoonmoon (258) is leader. Post Follow

1 Replies
3302 Views

Similar Articles

[PageSpeed] 54


"dfgdg dfgdfg" <sakirae@gmail.com> wrote in message 
news:i2tr4b$lp2$1@fred.mathworks.com...
> I'm an old C# user and new matlab gui user.I can define a global variable 
> easily in C# which can be recognized by all program not one function.
> I have tried some step for this operation;
> 1-I have defined the variable;
> global x;
> x=5;

If you MUST use global variables, then you need to declare the variable as 
global in EACH AND EVERY FUNCTION that you want to be able to access the 
variable from the global workspace.  However, using global variables is 
discouraged as they can cause problems that are difficult to diagnose and 
debug.

> 2-Then I wrote these code under; "function varargout = filename(varargin)" 
> which is located at top.It doesnt work.I couldn't use variable under other 
> functions.

That's correct.  Each function has its own workspace, and cannot (normally) 
access other function workspaces.

> 3-Then I have tried to write this code under;
>                "function filename_OpeningFcn(hObject, eventdata, handles, 
> varargin)"
> But It didn't work again.
> 4-Then I have tried to write this code under;
>                "function varargout = MH_OutputFcn(hObject, eventdata, 
> handles)"
> But It didn't work again and again.
>
> How can I fix this problem?Is there anyway for Matlab Gui?

I recommend using the techniques described in the documentation to share 
data amongst your GUI callback functions.

If you are using GUIDE:

http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f5-998197.html

If you are not using GUIDE:

http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f13-998197.html

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 

0
slord (13686)
8/3/2010 8:27:04 PM
Reply: