http://www.mathworks.com/matlabcentral/newsreader/view_thread/328576
MATLAB Central Newsreader  one simple question
Feed for thread: one simple question
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 25 Apr 2013 07:53:08 +0000
one simple question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328576#903164
ghasem
Hi.<br>
if I run two different matlab program with several similar parameters and subroutines,in two separate matlab windows simultaneously,(with addpath(genpath(...))), these similar parameters and subroutines have effect on other program?<br>
note that each full program is stored in separate folder in computer.<br>
for example :<br>
in both code I have "a" parameter,such that in first program a=10 and in second a=20.<br>
also,in both program I have " wh34_matlab.m" subroutine.<br>
now,when run these programs simultaneously,a=10 in first program, has effect on "a" value in second program?<br>
or,similarly,"details of wh34_matlab" subroutine has effect on "wh34_matlab" in other program?<br>
i.e,Values ??intersection does not occur?<br>
ghasem

Thu, 25 Apr 2013 11:45:52 +0000
Re: one simple question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328576#903178
Nasser M. Abbasi
On 4/25/2013 2:53 AM, ghasem wrote:<br>
<br>
> now,when run these programs simultaneously,a=10 in first program,<br>
>has effect on "a" value in second program?<br>
<br>
You should read this:<br>
<br>
<a href="http://www.mathworks.com/help/matlab/matlab_prog/baseandfunctionworkspaces.html">http://www.mathworks.com/help/matlab/matlab_prog/baseandfunctionworkspaces.html</a><br>
<br>
"Functions do not use the base workspace. Every function has<br>
its own function workspace. Each function workspace is separate<br>
from the base workspace and all other workspaces to protect the integrity of the data"<br>
<br>
Nasser

Thu, 25 Apr 2013 12:35:10 +0000
Re: one simple question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328576#903183
ghasem
> "Functions do not use the base workspace. Every function has<br>
> its own function workspace. Each function workspace is separate<br>
> from the base workspace and all other workspaces to protect the integrity of the data"<br>
> <br>
> Nasser<br>
========================<br>
So,they don't effect on each other?<br>
I must to note that I didn't create function.in fact I use from several subroutines that are call in one main program and by addpath(genpath('folder path')),I introduce subroutines path to matlab.<br>
I don't write a function,but used from script.

Fri, 26 Apr 2013 00:58:36 +0000
Re: one simple question
http://www.mathworks.com/matlabcentral/newsreader/view_thread/328576#903232
Nasser M. Abbasi
On 4/25/2013 7:35 AM, ghasem wrote:<br>
>> "Functions do not use the base workspace. Every function has<br>
>> its own function workspace. Each function workspace is separate<br>
>> from the base workspace and all other workspaces to protect the integrity of the data"<br>
>><br>
>> Nasser<br>
> ========================<br>
<br>
> So,they don't effect on each other?<br>
<br>
correct<br>
<br>
> I must to note that I didn't create function.in fact I use from<br>
>several subroutines that are call in one main program and by<br>
>addpath(genpath('folder path')),I introduce subroutines path to matlab.<br>
> I don't write a function,but used from script.<br>
><br>
<br>
It does not matter. Once a function returns, any variable<br>
it introduces inside it, will disappear after the function<br>
returns.<br>
<br>
Unless you are explicitly using global variables (i.e. using<br>
shared variables, `help global`), then a function can only be<br>
interfaced with via the calling parameters and the return<br>
variables, it returns, if any.<br>
<br>
when you write<br>
<br>
function foo(a,b)<br>
<br>
x=1<br>
....<br>
end<br>
<br>
This 'x' is gone for ever when the function returns. Another function<br>
doing the same will use a different 'x', local to it.<br>
<br>
This is not different really than any standard programming<br>
language. There are local variables and there are global<br>
variables and there are parameters, which are values<br>
passed between functions and there are function return values.<br>
<br>
Unless you use Classes in Matlab, there are the only things<br>
you need to worry about.<br>
<br>
And do not use shared global variables, they cause problems.<br>
<br>
Nasser