<?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: Deal or No Deal</title>
	<atom:link href="http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/</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>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Chris Adamson</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-32651</link>
		<dc:creator>Chris Adamson</dc:creator>
		<pubDate>Tue, 15 Nov 2011 05:07:02 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-32651</guid>
		<description>Loren,

That makes sense. I looked at the deal code and it confirmed what you said. However, it seems that the slowdown is in the lhs expansion of the cell array because I tried using the repmat version which is:

B = repmat({0}, 10000000, 1)

In the function
A = {0}

siz = [10000000, 1]
nelems = prod(double(siz))

B(nelems) = A
B(:) = A
these lines executed in no time.

But my point is is that B(nelems) = A
is allocating a large empty cell array and it does this quickly.

Even performing the line in deal for the scalar case

B = A(ones(nelems, 1));

is done fairly quickly.

Thanks for clearing it up Loren.</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>That makes sense. I looked at the deal code and it confirmed what you said. However, it seems that the slowdown is in the lhs expansion of the cell array because I tried using the repmat version which is:</p>
<p>B = repmat({0}, 10000000, 1)</p>
<p>In the function<br />
A = {0}</p>
<p>siz = [10000000, 1]<br />
nelems = prod(double(siz))</p>
<p>B(nelems) = A<br />
B(:) = A<br />
these lines executed in no time.</p>
<p>But my point is is that B(nelems) = A<br />
is allocating a large empty cell array and it does this quickly.</p>
<p>Even performing the line in deal for the scalar case</p>
<p>B = A(ones(nelems, 1));</p>
<p>is done fairly quickly.</p>
<p>Thanks for clearing it up Loren.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-32400</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 29 Jul 2011 10:59:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-32400</guid>
		<description>Chris-

I am not surprised.  In your first code, you are creating a cell array, turning it into a comma-separated list and listed 10000000 elements on the lhs of the equation.  Finally, you are filling each cell (with the same number).  The repmat version makes one 1x1 cell, the duplicates it into the large array once, without expanding and collapsing the cell array and its contents.  

If you were filling the lhs with lots of different values, where repmat wouldn&#039;t be appropriate, you might also find the speed improved versus the case where deal uses a single scalar input.  But I am not positive of that and don&#039;t have access to MATLAB to try it now.

Thanks.
--Loren</description>
		<content:encoded><![CDATA[<p>Chris-</p>
<p>I am not surprised.  In your first code, you are creating a cell array, turning it into a comma-separated list and listed 10000000 elements on the lhs of the equation.  Finally, you are filling each cell (with the same number).  The repmat version makes one 1&#215;1 cell, the duplicates it into the large array once, without expanding and collapsing the cell array and its contents.  </p>
<p>If you were filling the lhs with lots of different values, where repmat wouldn&#8217;t be appropriate, you might also find the speed improved versus the case where deal uses a single scalar input.  But I am not positive of that and don&#8217;t have access to MATLAB to try it now.</p>
<p>Thanks.<br />
&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Adamson</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-32392</link>
		<dc:creator>Chris Adamson</dc:creator>
		<pubDate>Mon, 25 Jul 2011 06:03:49 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-32392</guid>
		<description>Loren,

I find deal very slow for large cell arrays. For example,

&lt;pre&gt;
[A{1:10000000}] = deal(0);
&lt;/pre&gt;

takes ages.

It is something specific to deal since

&lt;pre&gt;
A = repmat({0}, 10000000, 1);
&lt;/pre&gt;

Executes pretty much instantaneously and produces a 10000000 element cell array with each element being the scalar 0. (i.e. the same output as the original deal call)</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>I find deal very slow for large cell arrays. For example,</p>
<pre>
[A{1:10000000}] = deal(0);
</pre>
<p>takes ages.</p>
<p>It is something specific to deal since</p>
<pre>
A = repmat({0}, 10000000, 1);
</pre>
<p>Executes pretty much instantaneously and produces a 10000000 element cell array with each element being the scalar 0. (i.e. the same output as the original deal call)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wei</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30237</link>
		<dc:creator>wei</dc:creator>
		<pubDate>Mon, 27 Apr 2009 19:03:12 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30237</guid>
		<description>Loren,
The loop is referring #14 where I have to index through cell array dparam to produce struct array x.

In #16 array x is da
&gt;&gt; da
 
da =
 
	Stateflow.Data: 1-by-3

From which I want to extract info to create a struct array sfData. Now I&#039;m thinking to avoid temp &#039;name&#039;.</description>
		<content:encoded><![CDATA[<p>Loren,<br />
The loop is referring #14 where I have to index through cell array dparam to produce struct array x.</p>
<p>In #16 array x is da<br />
&gt;&gt; da</p>
<p>da =</p>
<p>	Stateflow.Data: 1-by-3</p>
<p>From which I want to extract info to create a struct array sfData. Now I&#8217;m thinking to avoid temp &#8216;name&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30236</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 27 Apr 2009 18:32:22 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30236</guid>
		<description>Wei-

I don&#039;t know where you are talking about using a loop.  It&#039;s hard to tell what your final outcome is supposed to be.  For now, I can&#039;t tell if you can avoid the temporary variable, but is it really hurting anything?

--Loren</description>
		<content:encoded><![CDATA[<p>Wei-</p>
<p>I don&#8217;t know where you are talking about using a loop.  It&#8217;s hard to tell what your final outcome is supposed to be.  For now, I can&#8217;t tell if you can avoid the temporary variable, but is it really hurting anything?</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wei</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30235</link>
		<dc:creator>wei</dc:creator>
		<pubDate>Mon, 27 Apr 2009 18:29:15 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30235</guid>
		<description>Loren,
I was trying to avoid a loop. Thank you for answering. Could deal or else help to eliminate temp variable &#039;name&#039; below?

&gt;&gt; name = get(da,&#039;Name&#039;);
&gt;&gt; sfData = struct(&#039;Name&#039;,cell(3,1));
&gt;&gt; [sfData(:).Name]=name{:};</description>
		<content:encoded><![CDATA[<p>Loren,<br />
I was trying to avoid a loop. Thank you for answering. Could deal or else help to eliminate temp variable &#8216;name&#8217; below?</p>
<p>&gt;&gt; name = get(da,&#8217;Name&#8217;);<br />
&gt;&gt; sfData = struct(&#8216;Name&#8217;,cell(3,1));<br />
&gt;&gt; [sfData(:).Name]=name{:};</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30234</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 27 Apr 2009 17:32:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30234</guid>
		<description>Wei-

There does not seem to be any particular advantage to using deal with your data structure.

--Loren</description>
		<content:encoded><![CDATA[<p>Wei-</p>
<p>There does not seem to be any particular advantage to using deal with your data structure.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wei</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30233</link>
		<dc:creator>wei</dc:creator>
		<pubDate>Mon, 27 Apr 2009 17:05:47 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30233</guid>
		<description>Loren,
Question is if deal or better way to create structure array in the situation below? I tried but hadn&#039;t succeeded.

I have Stateflow.Data in a cell,
&gt;&gt; dparam

dparam = 

    [1x1 Stateflow.Data]    [2x1 Stateflow.Data]

Then I create a structure array x by

&gt;&gt;clear x; x=dparam{1}; x(2:3)=dparam{2};
Now I can perform
&gt;&gt; get(x,&#039;Name&#039;)

ans = 

    &#039;gain&#039;
    &#039;gain&#039;
    &#039;gain1&#039;</description>
		<content:encoded><![CDATA[<p>Loren,<br />
Question is if deal or better way to create structure array in the situation below? I tried but hadn&#8217;t succeeded.</p>
<p>I have Stateflow.Data in a cell,<br />
&gt;&gt; dparam</p>
<p>dparam = </p>
<p>    [1x1 Stateflow.Data]    [2x1 Stateflow.Data]</p>
<p>Then I create a structure array x by</p>
<p>&gt;&gt;clear x; x=dparam{1}; x(2:3)=dparam{2};<br />
Now I can perform<br />
&gt;&gt; get(x,&#8217;Name&#8217;)</p>
<p>ans = </p>
<p>    &#8216;gain&#8217;<br />
    &#8216;gain&#8217;<br />
    &#8216;gain1&#8242;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30138</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Wed, 25 Mar 2009 15:39:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30138</guid>
		<description>Loren,

I also contacted support who explained this in a little more detail.  

In reality, my data will not be shared in this way, so this becomes a non-issue.  Once I created a cell array with no shared cells, I got the performance characteristics I was expecting.

Many thanks,

Tom</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>I also contacted support who explained this in a little more detail.  </p>
<p>In reality, my data will not be shared in this way, so this becomes a non-issue.  Once I created a cell array with no shared cells, I got the performance characteristics I was expecting.</p>
<p>Many thanks,</p>
<p>Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30136</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 24 Mar 2009 18:23:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/#comment-30136</guid>
		<description>Tom-

Your test case is almost a worst-case scenario in that you are assigning all the cell values to the same array.  In the guts of MATLAB, these are all pointing to the same memory which slows the {:} operation down more than if the values were distinct.  In either case however there is quadratic performance as you observe (and the development team is aware of this).  Alas, I do not have a timeframe for changing this runtime characteristic.

The way to work around it is with a for loop, which should give linear speed with pre-allocation.  Not as pretty, but hopefully should help you out for now. 

--loren</description>
		<content:encoded><![CDATA[<p>Tom-</p>
<p>Your test case is almost a worst-case scenario in that you are assigning all the cell values to the same array.  In the guts of MATLAB, these are all pointing to the same memory which slows the {:} operation down more than if the values were distinct.  In either case however there is quadratic performance as you observe (and the development team is aware of this).  Alas, I do not have a timeframe for changing this runtime characteristic.</p>
<p>The way to work around it is with a for loop, which should give linear speed with pre-allocation.  Not as pretty, but hopefully should help you out for now. </p>
<p>&#8211;loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

