Why do I receive a run-time error when using the CLEAR function on a global variable in a stand-alone application?
Show older comments
I have discovered inconsistent behavior when I CLEAR a global variable within a function MATLAB file (e.g. foo.m) and within its compiled stand-alone executable (foo.exe).
This is my function MATLAB file called foo.m:
function foo
global a % declare global variable "a"
a = 1 % initialize "a"
subfoo % call my subfunction
function subfoo
global a % declare global variable "a"
a % get output of "a"
clear a % clear global variable "a"
global a % declare another global variable "a"
a % get the output of "a"
Here is the result of running my function MATLAB file within MATLAB:
a =
1
a =
1
a =
1
However, after I compile my MATLAB file foo.m into a stand-alone executable foo.exe, the result is the following output:
a =
1
a =
1
Undefined function or variable 'a'.
EXITING .
Why does the CLEAR statement on the global variable "a", actually clear the global variable in a stand-alone executable and cause the above error?
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!