<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Understanding Persistence</title>
	<atom:link href="http://blogs.mathworks.com/loren/2006/03/29/understanding-persistence/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2006/03/29/understanding-persistence/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Mon, 13 Feb 2012 13:24:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Jiro Doke</title>
		<link>http://blogs.mathworks.com/loren/2006/03/29/understanding-persistence/#comment-104</link>
		<dc:creator>Jiro Doke</dc:creator>
		<pubDate>Fri, 31 Mar 2006 13:40:54 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=30#comment-104</guid>
		<description>Thanks Loren! I&#039;ve been working mostly with R13, so I didn&#039;t know nested functions could be used in this way. So I guess when the function handle is created, the variables present during declaration remains in the function workspace. This is pretty useful.</description>
		<content:encoded><![CDATA[<p>Thanks Loren! I&#8217;ve been working mostly with R13, so I didn&#8217;t know nested functions could be used in this way. So I guess when the function handle is created, the variables present during declaration remains in the function workspace. This is pretty useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/03/29/understanding-persistence/#comment-102</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 30 Mar 2006 12:35:09 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=30#comment-102</guid>
		<description>&lt;p&gt;For grins, here&#039;s an example M-file using a nested function that loads in a data set for use over and over again.
&lt;/p&gt;
&lt;p&gt;
&lt;pre class=&quot;code&quot;&gt;
function fh = loadBig
% Contrived example to show how one might load a variable once and use it
% without using a PERSISTENT variable.

X = [];
caption = [];
map = [];
load clown
lmap = length(map);
h = image(X); colormap(map);
fh = @changePix;
    function changePix(i,j)
       X(i,j) = round(rand(length(i),length(j))*lmap);  % replace pix with random integers
       set(h,&#039;CData&#039;,X);
    end
end
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;
An advantage of this method over persistent is that I can have 2 function handles to this, with different data (don&#039;t hardwire in the filename, for example) and work on them simultaneously.  With the persistent solution, I can have only one instance.
&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>For grins, here&#8217;s an example M-file using a nested function that loads in a data set for use over and over again.
</p>
<p><pre class="code">
function fh = loadBig
% Contrived example to show how one might load a variable once and use it
% without using a PERSISTENT variable.

X = [];
caption = [];
map = [];
load clown
lmap = length(map);
h = image(X); colormap(map);
fh = @changePix;
    function changePix(i,j)
       X(i,j) = round(rand(length(i),length(j))*lmap);  % replace pix with random integers
       set(h,'CData',X);
    end
end
</pre>
</p>
<p>
An advantage of this method over persistent is that I can have 2 function handles to this, with different data (don&#8217;t hardwire in the filename, for example) and work on them simultaneously.  With the persistent solution, I can have only one instance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Markus</title>
		<link>http://blogs.mathworks.com/loren/2006/03/29/understanding-persistence/#comment-101</link>
		<dc:creator>Markus</dc:creator>
		<pubDate>Thu, 30 Mar 2006 10:45:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=30#comment-101</guid>
		<description>In my project, sometimes a function on a lower level needs some common parameter to work. Instead of handing over this parameter each time from function to function, I run this function once in the project initialization and save the parameter in a persistent variable. It looks like this:

function obj = whatever(obj, varargin)

persistent param1 param2

if length(varargin) &gt; 1
  param1 = obj.param1;
  param2 = obj.param2;
  return
end

The function is called with an extra argument in the initialization.</description>
		<content:encoded><![CDATA[<p>In my project, sometimes a function on a lower level needs some common parameter to work. Instead of handing over this parameter each time from function to function, I run this function once in the project initialization and save the parameter in a persistent variable. It looks like this:</p>
<p>function obj = whatever(obj, varargin)</p>
<p>persistent param1 param2</p>
<p>if length(varargin) &gt; 1<br />
  param1 = obj.param1;<br />
  param2 = obj.param2;<br />
  return<br />
end</p>
<p>The function is called with an extra argument in the initialization.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jiro Doke</title>
		<link>http://blogs.mathworks.com/loren/2006/03/29/understanding-persistence/#comment-100</link>
		<dc:creator>Jiro Doke</dc:creator>
		<pubDate>Thu, 30 Mar 2006 00:34:06 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=30#comment-100</guid>
		<description>I think there are other uses to persistent variables that can&#039;t be achieved by nested functions. I use it to load a large variable into the function space, so that subsequent calls will run faster. For example, in my FEX contribution, LOOK4 (http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9963&amp;objectType=file), I load a large mat file (which may take a few seconds) into persistent variable. Next time I run it, it returns the results instantly. What&#039;s a few seconds? I guess it&#039;s not that big of a deal, but I like the speed improvement.</description>
		<content:encoded><![CDATA[<p>I think there are other uses to persistent variables that can&#8217;t be achieved by nested functions. I use it to load a large variable into the function space, so that subsequent calls will run faster. For example, in my FEX contribution, LOOK4 (<a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9963&#038;objectType=file" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9963&#038;objectType=file</a>), I load a large mat file (which may take a few seconds) into persistent variable. Next time I run it, it returns the results instantly. What&#8217;s a few seconds? I guess it&#8217;s not that big of a deal, but I like the speed improvement.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/03/29/understanding-persistence/#comment-99</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 29 Mar 2006 18:21:40 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=30#comment-99</guid>
		<description>Depends how many times I ran it before.  If I&#039;d start from scratch, then &lt;kbd&gt;fcnPersist1(0)&lt;/kbd&gt; returns 0.  If I clear functions again right away and then run &lt;kbd&gt;fcnPersist1(3)&lt;/kbd&gt;, I get 3.  If I don&#039;t clear functions, after the call with 0 input, I get 3 as my output.</description>
		<content:encoded><![CDATA[<p>Depends how many times I ran it before.  If I&#8217;d start from scratch, then <kbd>fcnPersist1(0)</kbd> returns 0.  If I clear functions again right away and then run <kbd>fcnPersist1(3)</kbd>, I get 3.  If I don&#8217;t clear functions, after the call with 0 input, I get 3 as my output.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Roth</title>
		<link>http://blogs.mathworks.com/loren/2006/03/29/understanding-persistence/#comment-98</link>
		<dc:creator>Gary Roth</dc:creator>
		<pubDate>Wed, 29 Mar 2006 18:12:41 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=30#comment-98</guid>
		<description>Shouldn&#039;t fcnPersist1(0) evaluate to 0 and fcnPersist1(3) evaluate to 2?</description>
		<content:encoded><![CDATA[<p>Shouldn&#8217;t fcnPersist1(0) evaluate to 0 and fcnPersist1(3) evaluate to 2?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

