<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Nested Function Interaction with Global Variables</title>
	<link>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/</link>
	<description>Loren Shure  works on design of the MATLAB language at The MathWorks. She writes here about once a week on MATLAB programming and related topics. </description>
	<pubDate>Thu, 07 Aug 2008 23:50:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-29410</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 03 Jun 2008 11:42:57 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-29410</guid>
		<description>Vaclav-

You still get the memory savings applying the nested function outside the file.  But you do not need to use feval.  Simply pass the function handle, let's say fh, and evaluate it in your other program: fh(arg1,arg2).

--Loren</description>
		<content:encoded><![CDATA[<p>Vaclav-</p>
<p>You still get the memory savings applying the nested function outside the file.  But you do not need to use feval.  Simply pass the function handle, let&#8217;s say fh, and evaluate it in your other program: fh(arg1,arg2).</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vaclav</title>
		<link>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-29395</link>
		<dc:creator>Vaclav</dc:creator>
		<pubDate>Mon, 02 Jun 2008 13:14:36 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-29395</guid>
		<description>Loren:

Based on the discussions on nested functions on the Mathworks Blogs, I have rewritten my code to be 'nested' so as to avoid 'Out of Memory' problems when repeatedly passing large arrays to sub-functions. 

These sub-functions were originally used by different parent functions, hence it would be convenient to maintain a single source code for them. 

Do I achieve a similar benefit in terms of memory efficiency (avoid replication of memory space for large variables), if the nested sub-functions use "feval" to execute a code in a separate .m file? Is there any other solution ? (i am not sure i understand the matlab implementation of nesting properly).

Thanks

Vaclav</description>
		<content:encoded><![CDATA[<p>Loren:</p>
<p>Based on the discussions on nested functions on the Mathworks Blogs, I have rewritten my code to be &#8216;nested&#8217; so as to avoid &#8216;Out of Memory&#8217; problems when repeatedly passing large arrays to sub-functions. </p>
<p>These sub-functions were originally used by different parent functions, hence it would be convenient to maintain a single source code for them. </p>
<p>Do I achieve a similar benefit in terms of memory efficiency (avoid replication of memory space for large variables), if the nested sub-functions use &#8220;feval&#8221; to execute a code in a separate .m file? Is there any other solution ? (i am not sure i understand the matlab implementation of nesting properly).</p>
<p>Thanks</p>
<p>Vaclav</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-29185</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 20 May 2008 17:24:42 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-29185</guid>
		<description>Dmitry-

You might want to rearchitect your code so WrapperFun returns handles to the nested functions, perhaps in a struct or a cell array.  Then use those handles.

--Loren</description>
		<content:encoded><![CDATA[<p>Dmitry-</p>
<p>You might want to rearchitect your code so WrapperFun returns handles to the nested functions, perhaps in a struct or a cell array.  Then use those handles.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry Vedenov</title>
		<link>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-29184</link>
		<dc:creator>Dmitry Vedenov</dc:creator>
		<pubDate>Tue, 20 May 2008 17:17:07 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-29184</guid>
		<description>Loren:

I have a somewhat different problem with nested function, I am not sure what the solution could be. I have about six structurally identical nested functions within a wrapper function that takes as an in input a string with a name of the nested function to call, for example

function u = WrapperFun(u,funname)
...
function u = A()
...
end %A
function u = B()
...
end %B
...
end %WrapperFun

where funname can be 'A' or 'B'. I thought I can use feval(funname) to call the nested functions, but I am getting an error suggesting that feval cannot see the nested functions. Is there a different way to do this?

Thank you</description>
		<content:encoded><![CDATA[<p>Loren:</p>
<p>I have a somewhat different problem with nested function, I am not sure what the solution could be. I have about six structurally identical nested functions within a wrapper function that takes as an in input a string with a name of the nested function to call, for example</p>
<p>function u = WrapperFun(u,funname)<br />
&#8230;<br />
function u = A()<br />
&#8230;<br />
end %A<br />
function u = B()<br />
&#8230;<br />
end %B<br />
&#8230;<br />
end %WrapperFun</p>
<p>where funname can be &#8216;A&#8217; or &#8216;B&#8217;. I thought I can use feval(funname) to call the nested functions, but I am getting an error suggesting that feval cannot see the nested functions. Is there a different way to do this?</p>
<p>Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rehan</title>
		<link>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-26251</link>
		<dc:creator>Rehan</dc:creator>
		<pubDate>Thu, 14 Feb 2008 16:49:36 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-26251</guid>
		<description>Hi
I have built my code in MATLAB 7. I have a problem. I used global variables in the function for example img_global. Now by using imread, I get the input image and using imshow create an instance showing image. Later in the function, I create another using figure('Name', 'Label') alongwith the msgbox of the result. msgbox and seconf figure is there but first figure disappears. Please help</description>
		<content:encoded><![CDATA[<p>Hi<br />
I have built my code in MATLAB 7. I have a problem. I used global variables in the function for example img_global. Now by using imread, I get the input image and using imshow create an instance showing image. Later in the function, I create another using figure(&#8217;Name&#8217;, &#8216;Label&#8217;) alongwith the msgbox of the result. msgbox and seconf figure is there but first figure disappears. Please help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-37</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 21 Feb 2006 10:25:54 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-37</guid>
		<description>&lt;p&gt;Nested functions are a new feature in MATLAB 7 which is why the code didn't work in MATLAB 6 when you tried it there.  
&lt;/p&gt;
&lt;p&gt;
I recommend you read the &lt;a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/global.html" rel="nofollow"&gt;documentation&lt;/a&gt; on using global variables to understand how to access them.  In each workspace that you want to see a particular global variable, you must declare that before making reference to it.  This includes functions and the base workspace.
&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Nested functions are a new feature in MATLAB 7 which is why the code didn&#8217;t work in MATLAB 6 when you tried it there.
</p>
<p>
I recommend you read the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/global.html" rel="nofollow">documentation</a> on using global variables to understand how to access them.  In each workspace that you want to see a particular global variable, you must declare that before making reference to it.  This includes functions and the base workspace.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DavidB</title>
		<link>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-35</link>
		<dc:creator>DavidB</dc:creator>
		<pubDate>Fri, 17 Feb 2006 05:26:25 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/02/15/nested-function-interaction-with-global-variables/#comment-35</guid>
		<description>Hi, I think your example with nested are nice and i cant do the same.
I am running Matlab6 but no way to share variable efficiently
-for exemple I run the nested function 'taxdemo'
taxDemo(30) %%Matlab example
" ??? Undefined function or variable 'AdjustedIncome'."

Furthermore, when I am inside a function into i cannot access global variables defined in the main workspace, with the exception of nested global variables, for exemple somthing like that:
function param=opt(goal)
global G
G=goal;
.....
param = lsqnonlin(@circuit,Z0,LB,HB,cond); 
   function F = circuit(Z)
    %acces global
   end
end</description>
		<content:encoded><![CDATA[<p>Hi, I think your example with nested are nice and i cant do the same.<br />
I am running Matlab6 but no way to share variable efficiently<br />
-for exemple I run the nested function &#8216;taxdemo&#8217;<br />
taxDemo(30) %%Matlab example<br />
&#8221; ??? Undefined function or variable &#8216;AdjustedIncome&#8217;.&#8221;</p>
<p>Furthermore, when I am inside a function into i cannot access global variables defined in the main workspace, with the exception of nested global variables, for exemple somthing like that:<br />
function param=opt(goal)<br />
global G<br />
G=goal;<br />
&#8230;..<br />
param = lsqnonlin(@circuit,Z0,LB,HB,cond);<br />
   function F = circuit(Z)<br />
    %acces global<br />
   end<br />
end</p>
]]></content:encoded>
	</item>
</channel>
</rss>
