Reputation: 3
I'm studying a MATLAB code in which I found this:
GLOBAL = eye(4,4);
what is GLOBAL
? Is it a global variable? Documentation says that global variables are declared in this way:
global x1 = 4;
What are the differences between GLOBAL
and global
?
Upvotes: 0
Views: 70
Reputation: 1077
I wrote a little script which highlights the difference:
clear all;
global x1;
x1 = 4;
GLOBAL = eye(4,4);
whos
As you can see in the workspace x1
is a global variable, whereas GLOBAL
is not:
Name Size Bytes Class Attributes
GLOBAL 4x4 128 double
x1 1x1 8 double global
Edit: you could even declare GLOBAL
globally: global GLOBAL
which then leads to:
Name Size Bytes Class Attributes
GLOBAL 4x4 128 double global
x1 1x1 8 double global
Upvotes: 2
Reputation: 18177
GLOBAL = eye(4,4);
indeed makes GLOBAL
a variable. This is not too bad, as MATLAB is case sensitive, though not very clear of course. The documented version you found is global
in lower case. I'd suggest not naming variables the same as built-in functions, e.g. if you calculate a sum don't call it sum
but Summed
or something; don't call an average mean
, but Avg
etc.
Upvotes: 3