Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
global varaible declaration

Subject: global varaible declaration

From: Marcio Barbalho

Date: 5 Mar, 2010 18:48:19

Message: 1 of 3

Dear friends..

I want variable 'x' to work as global, I declared it in the main program and it is not working in an auxiliary function

main m-file:
-----------------------------------
global x
x = pi;
z = pi/4;
y = myfun(z);
c = x + y
----------------------------------

auxiliary m-file function:
----------------------------------
function f = myfun(k)
k = x - pi;
f = sin(k);
----------------------------------

Could you please find the bug?

Subject: global varaible declaration

From: Matt Fig

Date: 5 Mar, 2010 18:53:19

Message: 2 of 3

As stated in the help for GLOBAL, you must declare a global variable in every workspace which uses it.

Subject: global varaible declaration

From: Marcio Barbalho

Date: 5 Mar, 2010 19:26:25

Message: 3 of 3

many thanks

Tags for this Thread

No tags are associated with this thread.

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.

Contact us