<?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: MATLAB Basics: Array of structures vs Structures of arrays</title>
	<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/</link>
	<description>&#60;a href="http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=969735&#38;objectType=author"&#62;Bob&#60;/a&#62;, &#60;a href="http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1093599&#38;objectType=author"&#62;Brett&#60;/a&#62; &#38; &#60;a href="http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094142&#38;objectType=author"&#62;Jiro&#60;/a&#62; share favorite user-contributed submissions from the File Exchange.</description>
	<pubDate>Mon, 23 Nov 2009 01:24:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Dan</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13221</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Tue, 04 Aug 2009 19:55:46 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13221</guid>
		<description>I may be wrong, but one of the examples in Post 4 (Ryan Gray) doesn't work as advertised. Specifically,
&lt;pre&gt;
[structArray(1:length(array)).fieldname] = deal(num2cell(array))
&lt;/pre&gt;
ends up assigning the whole array to every instance of fieldname, instead of distributing the array across those instances. What does seem to work is:
&lt;pre&gt;
cell_array = num2cell(array);
[structArray(1:length(array)).fieldname] = cell_array{:};
&lt;/pre&gt;
I leave it as an exercise for a MATLAB guru to splain why this is the case.</description>
		<content:encoded><![CDATA[<p>I may be wrong, but one of the examples in Post 4 (Ryan Gray) doesn&#8217;t work as advertised. Specifically,</p>
<pre>
[structArray(1:length(array)).fieldname] = deal(num2cell(array))
</pre>
<p>ends up assigning the whole array to every instance of fieldname, instead of distributing the array across those instances. What does seem to work is:</p>
<pre>
cell_array = num2cell(array);
[structArray(1:length(array)).fieldname] = cell_array{:};
</pre>
<p>I leave it as an exercise for a MATLAB guru to splain why this is the case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13157</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 14 May 2009 19:19:49 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13157</guid>
		<description>You want to use a cell array here:

&lt;pre class="code"&gt;

s{1} = s0
s{2} = s1
s{1}.field1
s{1}.field1(1,3)

&lt;/pre&gt;

Doug</description>
		<content:encoded><![CDATA[<p>You want to use a cell array here:</p>
<pre class="code">

s{1} = s0
s{2} = s1
s{1}.field1
s{1}.field1(1,3)
</pre>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: liuzhi</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13155</link>
		<dc:creator>liuzhi</dc:creator>
		<pubDate>Thu, 14 May 2009 13:36:43 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13155</guid>
		<description>In one of my program, I'd like to use an array of array of structures, such like
&lt;pre&gt;
s0 = struct('field1', [v1 v2], 'field2', [v3 v4]);
s1 = struct('field1', [v1' v2'], 'field2', [v3' v4']);
&lt;/pre&gt;
I want another data structure s = [s0, s1] so that I can access s0(1) like s(0,1). How can I do that?</description>
		<content:encoded><![CDATA[<p>In one of my program, I&#8217;d like to use an array of array of structures, such like</p>
<pre>
s0 = struct('field1', [v1 v2], 'field2', [v3 v4]);
s1 = struct('field1', [v1' v2'], 'field2', [v3' v4']);
</pre>
<p>I want another data structure s = [s0, s1] so that I can access s0(1) like s(0,1). How can I do that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Gray</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-10942</link>
		<dc:creator>Ryan Gray</dc:creator>
		<pubDate>Thu, 24 Apr 2008 19:31:14 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-10942</guid>
		<description>If you have an array that you want to assign to a field across a structure array, you can do this:

[structArray(:).fieldname] = deal(num2cell(array))

Of course, the length of array should be the same as the length of structArray, but if structArray doesn't exist yet, then you can do:

[structArray(1:length(array)).fieldname] = deal(num2cell(array))

If array is already a cell array, you can avoid using both deal and num2cell (although they will still work) and use:

[structArray(:).fieldname] = array{:}
or
[structArray(1:length(array)).fieldname] = array{:}

An example, modifying the struct array 'people' from the video:

names = {'Larry','Moe','Curly'};
[people(:).name] = names{:};</description>
		<content:encoded><![CDATA[<p>If you have an array that you want to assign to a field across a structure array, you can do this:</p>
<p>[structArray(:).fieldname] = deal(num2cell(array))</p>
<p>Of course, the length of array should be the same as the length of structArray, but if structArray doesn&#8217;t exist yet, then you can do:</p>
<p>[structArray(1:length(array)).fieldname] = deal(num2cell(array))</p>
<p>If array is already a cell array, you can avoid using both deal and num2cell (although they will still work) and use:</p>
<p>[structArray(:).fieldname] = array{:}<br />
or<br />
[structArray(1:length(array)).fieldname] = array{:}</p>
<p>An example, modifying the struct array &#8216;people&#8217; from the video:</p>
<p>names = {&#8217;Larry&#8217;,'Moe&#8217;,'Curly&#8217;};<br />
[people(:).name] = names{:};</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-10906</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Wed, 23 Apr 2008 13:01:19 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-10906</guid>
		<description>Emil,

Yes, you are correct.  I can not believe I over looked that.  There are so many ways to do certain things in MATLAB.

Doug</description>
		<content:encoded><![CDATA[<p>Emil,</p>
<p>Yes, you are correct.  I can not believe I over looked that.  There are so many ways to do certain things in MATLAB.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-10897</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Tue, 22 Apr 2008 21:29:00 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-10897</guid>
		<description>This and Emil's comment were quite helpful to me.

To take this one step further, one advantage of Arrays of Structures would be the ability to have vectors of different lengths for each numerical part, and a cell array of names of different lengths for each name part.

For example:

people(1).name='Erin'
people(2).name={'Joan' 'Carla'}
people(1).sim=44
people(2).sim=[561 49]</description>
		<content:encoded><![CDATA[<p>This and Emil&#8217;s comment were quite helpful to me.</p>
<p>To take this one step further, one advantage of Arrays of Structures would be the ability to have vectors of different lengths for each numerical part, and a cell array of names of different lengths for each name part.</p>
<p>For example:</p>
<p>people(1).name=&#8217;Erin&#8217;<br />
people(2).name={&#8217;Joan&#8217; &#8216;Carla&#8217;}<br />
people(1).sim=44<br />
people(2).sim=[561 49]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emil</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-10895</link>
		<dc:creator>Emil</dc:creator>
		<pubDate>Tue, 22 Apr 2008 18:54:15 +0000</pubDate>
		<guid>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-10895</guid>
		<description>It's easier to create vector s by:
s = [people.SimmNum];</description>
		<content:encoded><![CDATA[<p>It&#8217;s easier to create vector s by:<br />
s = [people.SimmNum];</p>
]]></content:encoded>
	</item>
</channel>
</rss>
