f



How to use a global variable in Matlab GUI

Hi NG

Following code wont work. I cant use a global variable like "h" in my
function.

******************************************
h=100;

function slider1_Callback(hObject, eventdata, handles)

a=10;
b=h*a;
******************************************

Anyone can help me with that problem?

Regards
AHR


0
ahr4176 (6)
5/14/2004 4:10:26 PM
comp.soft-sys.matlab 211266 articles. 14 followers. lunamoonmoon (258) is leader. Post Follow

2 Replies
368 Views

Similar Articles

[PageSpeed] 59

global h;

also use
whos global
to check.

Meenakshi Matai
DSP Systems Engineer
Signalogic Inc.

AHR wrote:
>
>
> Hi NG
>
> Following code wont work. I cant use a global variable like "h" in
> my
> function.
>
> ******************************************
> h=100;
>
> function slider1_Callback(hObject, eventdata, handles)
>
> a=10;
> b=h*a;
> ******************************************
>
> Anyone can help me with that problem?
>
> Regards
> AHR
>
>
>
0
mmatai (11)
5/14/2004 4:52:42 PM
On Fri, 14 May 2004 18:10:26 +0200, "AHR" <ahr@xx.xx> wrote:

>Hi NG
>
>Following code wont work. I cant use a global variable like "h" in my
>function.
>
>******************************************
>h=100;
>
>function slider1_Callback(hObject, eventdata, handles)
>
>a=10;
>b=h*a;
>******************************************
Using global variables in not recommended by Mathworks and prociples of
robust programming, is much better using the "userdata" field in hObject
variable which is passed to all callbacks.

hObject.userdata.h = <value>


David
Ciao
David
0
71david (79)
5/15/2004 6:19:47 AM
Reply: