f



How to handle global variables in Matlab script file using Matlab Compiler?

Dear All:

I am trying to using Matlab Compiler 4.0 to make our Matlab
application to a Stand-Alone application. But I meet one problem,
that is in our Matlab program we used a script file to call several
functions, so this script file works as a main interface file. And we
need declare few global variables to perform some functions. But as
you know, the compiler can not work with Matlab script file, but if I
put my Matlab script file into a function, it seems the global
variables not work any more. Does anyone know how to handle this
problems? Thanks so much for your help!

Thanks ........................

Shuang.
0
sjia (3)
4/28/2005 5:07:31 PM
comp.soft-sys.matlab 211266 articles. 24 followers. lunamoonmoon (257) is leader. Post Follow

3 Replies
985 Views

Similar Articles

[PageSpeed] 42

This is how it works:

In your main function a variable "tmp" is declared as a GLOBAL
variable.

In order to use the GLOBAL variable "tmp" declared in the main
function, in other functions. You need to declare the variable "tmp"
as GLOBAL in other functions too. This is called "global scope".

Shuang Jia wrote:
>
>
> Dear All:
>
> I am trying to using Matlab Compiler 4.0 to make our Matlab
> application to a Stand-Alone application. But I meet one problem,
> that is in our Matlab program we used a script file to call several
> functions, so this script file works as a main interface file. And
> we
> need declare few global variables to perform some functions. But as
> you know, the compiler can not work with Matlab script file, but if
> I
> put my Matlab script file into a function, it seems the global
> variables not work any more. Does anyone know how to handle this
> problems? Thanks so much for your help!
>
> Thanks ........................
>
> Shuang.
0
kingjew (58)
4/28/2005 5:38:53 PM
Thanks for your answer. BTW, do I need to declare the "tmp" in every
subfunction, even they do not use the global variable "tmp"? In my
case I did declare the global variables in the subfunction that use
it, not every subfunction. I am thinking that the problem here is
when I declare the global variables with a matlab function, not a
script file (since Matlab compiler can not compile Matlab script
file), so the global variables are not global any more. Do you think
so?

thanks.

Shuang.

Vasco M wrote:
>
>
> This is how it works:
>
> In your main function a variable "tmp" is declared as a GLOBAL
> variable.
>
> In order to use the GLOBAL variable "tmp" declared in the main
> function, in other functions. You need to declare the variable
> "tmp"
> as GLOBAL in other functions too. This is called "global scope".
>
> Shuang Jia wrote:
>>
>>
>> Dear All:
>>
>> I am trying to using Matlab Compiler 4.0 to make our Matlab
>> application to a Stand-Alone application. But I meet one
problem,
>> that is in our Matlab program we used a script file to call
> several
>> functions, so this script file works as a main interface file.
> And
>> we
>> need declare few global variables to perform some functions.
But
> as
>> you know, the compiler can not work with Matlab script file,
but
> if
>> I
>> put my Matlab script file into a function, it seems the global
>> variables not work any more. Does anyone know how to handle
this
>> problems? Thanks so much for your help!
>>
>> Thanks ........................
>>
>> Shuang.
0
sjia (3)
4/28/2005 6:34:50 PM
When you use a script file, all variables are stored in the
workspace. So, all script files have access to the workspace.

With functions is different. Functions can't access the workspace.
You can store variables in UICONTROL, save them to .mat files or
declared them as global. Makes no sense to declare a variable global
if you are not going to use in a function. I'm not sure how the
compiler interprets global variables.

Shuang Jia wrote:
>
>
> Thanks for your answer. BTW, do I need to declare the "tmp" in
> every
> subfunction, even they do not use the global variable "tmp"? In my
> case I did declare the global variables in the subfunction that use
> it, not every subfunction. I am thinking that the problem here is
> when I declare the global variables with a matlab function, not a
> script file (since Matlab compiler can not compile Matlab script
> file), so the global variables are not global any more. Do you
> think
> so?
>
> thanks.
>
> Shuang.
>
> Vasco M wrote:
>>
>>
>> This is how it works:
>>
>> In your main function a variable "tmp" is declared as a GLOBAL
>> variable.
>>
>> In order to use the GLOBAL variable "tmp" declared in the main
>> function, in other functions. You need to declare the variable
>> "tmp"
>> as GLOBAL in other functions too. This is called "global
scope".
>>
>> Shuang Jia wrote:
>>>
>>>
>>> Dear All:
>>>
>>> I am trying to using Matlab Compiler 4.0 to make our Matlab
>>> application to a Stand-Alone application. But I meet one
> problem,
>>> that is in our Matlab program we used a script file to call
>> several
>>> functions, so this script file works as a main interface
> file.
>> And
>>> we
>>> need declare few global variables to perform some
functions.
> But
>> as
>>> you know, the compiler can not work with Matlab script
file,
> but
>> if
>>> I
>>> put my Matlab script file into a function, it seems the
> global
>>> variables not work any more. Does anyone know how to handle
> this
>>> problems? Thanks so much for your help!
>>>
>>> Thanks ........................
>>>
>>> Shuang.
0
kingjew (58)
4/28/2005 7:10:16 PM
Reply: