<?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: Structures and Comma-Separated Lists</title>
	<atom:link href="http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/</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>Wed, 08 May 2013 12:21:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-32923</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Thu, 19 Jan 2012 16:20:56 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-32923</guid>
		<description><![CDATA[Basawaraj-

I don&#039;t know if this would work, but you could store each string in the row of an array, padding with blanks at the right end if need be.  Then loop through the rows to get each string and work with it.

--Loren]]></description>
		<content:encoded><![CDATA[<p>Basawaraj-</p>
<p>I don&#8217;t know if this would work, but you could store each string in the row of an array, padding with blanks at the right end if need be.  Then loop through the rows to get each string and work with it.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Basawaraj</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-32914</link>
		<dc:creator>Basawaraj</dc:creator>
		<pubDate>Wed, 18 Jan 2012 02:41:15 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-32914</guid>
		<description><![CDATA[Hi Loren,

I have been using the sort of code given below (taken from response 7) to write values to specific field of the struct array, and it has been working great.


newNums = [19, 2];
newNumsc = num2cell(newNums);
[s1.FavoriteNumber] = newNumsc{:};


I am now trying to convert my functions into C/C++ using Matlab Codegen. I get an error stating that &quot;Code generation only supports cell operations for varargin and varargout&quot;. Is there a way to do the same without using cell operation? Especially something this is similar (i.e., a vectorized operation/code).]]></description>
		<content:encoded><![CDATA[<p>Hi Loren,</p>
<p>I have been using the sort of code given below (taken from response 7) to write values to specific field of the struct array, and it has been working great.</p>
<p>newNums = [19, 2];<br />
newNumsc = num2cell(newNums);<br />
[s1.FavoriteNumber] = newNumsc{:};</p>
<p>I am now trying to convert my functions into C/C++ using Matlab Codegen. I get an error stating that &#8220;Code generation only supports cell operations for varargin and varargout&#8221;. Is there a way to do the same without using cell operation? Especially something this is similar (i.e., a vectorized operation/code).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jake</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-32316</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Mon, 13 Jun 2011 16:32:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-32316</guid>
		<description><![CDATA[Charles and Paul,

I was encountering the same &quot;scalar index required for this type of multi-level indexing&quot; error, so I wrote a function called multiLevelStructMat that can construct the desired matrix from the struct array, assuming the field has numeric values at the proper place. Give it a try, I hope it helps.

http://www.mathworks.com/matlabcentral/fileexchange/31759-multilevelstructmat]]></description>
		<content:encoded><![CDATA[<p>Charles and Paul,</p>
<p>I was encountering the same &#8220;scalar index required for this type of multi-level indexing&#8221; error, so I wrote a function called multiLevelStructMat that can construct the desired matrix from the struct array, assuming the field has numeric values at the proper place. Give it a try, I hope it helps.</p>
<p><a href="http://www.mathworks.com/matlabcentral/fileexchange/31759-multilevelstructmat" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/31759-multilevelstructmat</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-32215</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 28 Apr 2011 17:32:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-32215</guid>
		<description><![CDATA[Paul,

I believe I&#039;ve covered this before - there is no guarantee that the next level down in structures is at all uniform.  One might contain another struct, another a string, some other ones numeric values with different dimensions.  It&#039;s not clear how to concatenate those and we didn&#039;t want to design something that worked sometimes but not always.

--Loren]]></description>
		<content:encoded><![CDATA[<p>Paul,</p>
<p>I believe I&#8217;ve covered this before &#8211; there is no guarantee that the next level down in structures is at all uniform.  One might contain another struct, another a string, some other ones numeric values with different dimensions.  It&#8217;s not clear how to concatenate those and we didn&#8217;t want to design something that worked sometimes but not always.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul W</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-32214</link>
		<dc:creator>Paul W</dc:creator>
		<pubDate>Thu, 28 Apr 2011 17:08:04 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-32214</guid>
		<description><![CDATA[Dear Loren:

Why is multi-level indexing forbidden when extracting information for structure arrays? For instance:

&lt;pre&gt;
politicians = [struct( &#039;name&#039;, &#039;McCain&#039;, &#039;assets&#039;, struct(&#039;house_num&#039;,8,&#039;boatnum&#039;,1)),...
    struct( &#039;name&#039;, &#039;Palin&#039;, &#039;assets&#039;, struct(&#039;house_num&#039;,1,&#039;boatnum&#039;,1))];

% we can access fields at the top level
politicians(:).name

% but a scalar index required for this type of multi-level indexing.
politicians(:).assets.house_num  

&lt;/pre&gt;

   Thanks,

   Paul]]></description>
		<content:encoded><![CDATA[<p>Dear Loren:</p>
<p>Why is multi-level indexing forbidden when extracting information for structure arrays? For instance:</p>
<pre>
politicians = [struct( 'name', 'McCain', 'assets', struct('house_num',8,'boatnum',1)),...
    struct( 'name', 'Palin', 'assets', struct('house_num',1,'boatnum',1))];

% we can access fields at the top level
politicians(:).name

% but a scalar index required for this type of multi-level indexing.
politicians(:).assets.house_num  

</pre>
<p>   Thanks,</p>
<p>   Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-31018</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 27 Jan 2010 15:44:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-31018</guid>
		<description><![CDATA[Allan-

If the fields have shared data, MATLAB may do some extra work.  In a real example, where each field has different data that aren&#039;t linked, I don&#039;t think you should see this disparity in performance.  Do you?  Can you write a very small code snippet to demonstrate the issue?

--Loren]]></description>
		<content:encoded><![CDATA[<p>Allan-</p>
<p>If the fields have shared data, MATLAB may do some extra work.  In a real example, where each field has different data that aren&#8217;t linked, I don&#8217;t think you should see this disparity in performance.  Do you?  Can you write a very small code snippet to demonstrate the issue?</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allan Lyckegaard</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-31014</link>
		<dc:creator>Allan Lyckegaard</dc:creator>
		<pubDate>Tue, 26 Jan 2010 22:23:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-31014</guid>
		<description><![CDATA[@Todd &amp; Loren,

about reply 40/41. I have experienced the same behaviour as Todd. I have a very large structure R (~200 MB, output from a database query, random numbers) with 8 fields and length ~1.3e6.

If I try to extract a single fields with
&lt;pre&gt;
omega = [R.omega]&#039;
&lt;/pre&gt;
it takes 10 minuttes. If I do what Todd suggest and looping over the structure it takes 2 seconds or so. But the fastest is to do
&lt;pre&gt;
omega = [R(1:end).omega]&#039;
&lt;/pre&gt;
which takes 0.6 seconds.

It is of course great that I have gained a 600 times speed improvement but it is not logical why I need to include the indices?

-Allan]]></description>
		<content:encoded><![CDATA[<p>@Todd &amp; Loren,</p>
<p>about reply 40/41. I have experienced the same behaviour as Todd. I have a very large structure R (~200 MB, output from a database query, random numbers) with 8 fields and length ~1.3e6.</p>
<p>If I try to extract a single fields with</p>
<pre>
omega = [R.omega]'
</pre>
<p>it takes 10 minuttes. If I do what Todd suggest and looping over the structure it takes 2 seconds or so. But the fastest is to do</p>
<pre>
omega = [R(1:end).omega]'
</pre>
<p>which takes 0.6 seconds.</p>
<p>It is of course great that I have gained a 600 times speed improvement but it is not logical why I need to include the indices?</p>
<p>-Allan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30966</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 11 Jan 2010 19:28:43 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-30966</guid>
		<description><![CDATA[Charles-

I am having trouble understanding what you actually want to do.  I used maxx = 3 and maxy = 5, and your array has all zeros.  My suggestion is to convert your struct to a cellarray and try to use cellfun or accumarray to achieve your results.

--Loren]]></description>
		<content:encoded><![CDATA[<p>Charles-</p>
<p>I am having trouble understanding what you actually want to do.  I used maxx = 3 and maxy = 5, and your array has all zeros.  My suggestion is to convert your struct to a cellarray and try to use cellfun or accumarray to achieve your results.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30958</link>
		<dc:creator>Charles</dc:creator>
		<pubDate>Fri, 08 Jan 2010 08:38:54 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-30958</guid>
		<description><![CDATA[Correction:   (oops, multiple errors in for loop above)

&lt;pre&gt;
PDsum=0;
for i=1:size(PD,2)
    PDsum = PDsum + PD(1,i,1).in.arrayX;
end;
&lt;/pre)
This for loop correctly sums the arrayX arrays.]]></description>
		<content:encoded><![CDATA[<p>Correction:   (oops, multiple errors in for loop above)</p>
<pre>
PDsum=0;<br />
for i=1:size(PD,2)<br />
    PDsum = PDsum + PD(1,i,1).in.arrayX;<br />
end;<br />
&lt;/pre)<br />
This for loop correctly sums the arrayX arrays.
</pre>]]></content:encoded>
	</item>
	<item>
		<title>By: Charles</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30957</link>
		<dc:creator>Charles</dc:creator>
		<pubDate>Fri, 08 Jan 2010 08:10:55 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=39#comment-30957</guid>
		<description><![CDATA[Correction:  precede the above for loop with  PDsum=0;]]></description>
		<content:encoded><![CDATA[<p>Correction:  precede the above for loop with  PDsum=0;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
