<?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: MATLAB Basics: Array of structures vs Structures of arrays</title>
	<atom:link href="http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/</link>
	<description>&#60;a href=&#34;http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1093599&#38;objectType=author&#34;&#62;Brett&#60;/a&#62; &#38; &#60;a href=&#34;http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=1094142&#38;objectType=author&#34;&#62;Jiro&#60;/a&#62; share favorite user-contributed submissions from the File Exchange.</description>
	<lastBuildDate>Fri, 10 Feb 2012 16:12:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Paul Torek</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14371</link>
		<dc:creator>Paul Torek</dc:creator>
		<pubDate>Mon, 19 Dec 2011 20:45:24 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14371</guid>
		<description>Thankyou thankyou thankyou!

You gave me the direction I needed to extract relevant info from the matlab &lt;i&gt;dir filename&lt;/i&gt; command.  Such as:


function Subdirs = OneLevelSubDirs(directory,match)
% xxx Need Help xxx
% Subdirs = OneLevelSubDirs(directory,match)

if nargin &lt; 2 &#124;&#124; isempty(match)
    match = &#039;*&#039;;
end

X = dir(directory);

Xdir = {X(:).name};
Xdir = Xdir(find(cell2mat({X(:).isdir})));
Subdirs = Xdir(~cellfun(@(x)ismember(x,{&#039;.&#039;;&#039;..&#039;}),Xdir));


Did I mention thank you?</description>
		<content:encoded><![CDATA[<p>Thankyou thankyou thankyou!</p>
<p>You gave me the direction I needed to extract relevant info from the matlab <i>dir filename</i> command.  Such as:</p>
<p>function Subdirs = OneLevelSubDirs(directory,match)<br />
% xxx Need Help xxx<br />
% Subdirs = OneLevelSubDirs(directory,match)</p>
<p>if nargin &lt; 2 || isempty(match)<br />
    match = &#039;*&#039;;<br />
end</p>
<p>X = dir(directory);</p>
<p>Xdir = {X(:).name};<br />
Xdir = Xdir(find(cell2mat({X(:).isdir})));<br />
Subdirs = Xdir(~cellfun(@(x)ismember(x,{&#039;.&#039;;&#039;..&#039;}),Xdir));</p>
<p>Did I mention thank you?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nick</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14271</link>
		<dc:creator>nick</dc:creator>
		<pubDate>Thu, 13 Oct 2011 15:43:16 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14271</guid>
		<description>hi
i am new in MATLAB, can u plz tell whats d problem with the following statements (i need to assign an array of integers to a member of an array of structures )
    n(1).loc=[x-1 y+1];
    n(2).loc=[x y+1];
    n(3).loc=[x+1 y+1];
    n(4).loc=[x+1 y];
    n(5).loc=[x+1 y-1];
why are these assignments wrong?? plz reply ASAP... thnx</description>
		<content:encoded><![CDATA[<p>hi<br />
i am new in MATLAB, can u plz tell whats d problem with the following statements (i need to assign an array of integers to a member of an array of structures )<br />
    n(1).loc=[x-1 y+1];<br />
    n(2).loc=[x y+1];<br />
    n(3).loc=[x+1 y+1];<br />
    n(4).loc=[x+1 y];<br />
    n(5).loc=[x+1 y-1];<br />
why are these assignments wrong?? plz reply ASAP&#8230; thnx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Omar</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14249</link>
		<dc:creator>Omar</dc:creator>
		<pubDate>Tue, 27 Sep 2011 21:36:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14249</guid>
		<description>I want to have a .wav file into a vector so I can create de Spectra with the SPtool.

When I use the wavread() function and  import the data into sptool it say thats an [array] so i couldnt create the spectrum, this tool only work with vectors. So how can i turn this array into vector? 

a little help here please</description>
		<content:encoded><![CDATA[<p>I want to have a .wav file into a vector so I can create de Spectra with the SPtool.</p>
<p>When I use the wavread() function and  import the data into sptool it say thats an [array] so i couldnt create the spectrum, this tool only work with vectors. So how can i turn this array into vector? </p>
<p>a little help here please</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve L</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14217</link>
		<dc:creator>Steve L</dc:creator>
		<pubDate>Fri, 19 Aug 2011 13:16:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14217</guid>
		<description>Annon,

To do this you can use DEAL, but I think Doug&#039;s question is a good one: why do you need/want to do it this way?

&lt;pre&gt;
% Make sure people2 doesn&#039;t exist yet
% This way you can tell that the command performed
% the initial creation correctly
clear people2

% Define the cell array of names
S = {&#039;bob&#039;, &#039;john&#039;};

% DEAL the elements of the cell into the struct
[people2(1:2).name] = deal(S{:})
&lt;/pre&gt;

If you&#039;re using release R14 or later, you can omit the DEAL as described in the &lt;a href=&quot;http://www.mathworks.com/help/techdoc/rn/f8-1009921.html#f8-1013499&quot; rel=&quot;nofollow&quot;&gt;Release Notes&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>Annon,</p>
<p>To do this you can use DEAL, but I think Doug&#8217;s question is a good one: why do you need/want to do it this way?</p>
<pre>
% Make sure people2 doesn't exist yet
% This way you can tell that the command performed
% the initial creation correctly
clear people2

% Define the cell array of names
S = {'bob', 'john'};

% DEAL the elements of the cell into the struct
[people2(1:2).name] = deal(S{:})
</pre>
<p>If you&#8217;re using release R14 or later, you can omit the DEAL as described in the <a href="http://www.mathworks.com/help/techdoc/rn/f8-1009921.html#f8-1013499" rel="nofollow">Release Notes</a>.</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-14215</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Fri, 12 Aug 2011 19:09:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14215</guid>
		<description>@Annon,

I do not know of a way to do that.  You seem to be able to get the data in in other ways, why is it important to do it in this particular manner?

Doug</description>
		<content:encoded><![CDATA[<p>@Annon,</p>
<p>I do not know of a way to do that.  You seem to be able to get the data in in other ways, why is it important to do it in this particular manner?</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: annon</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14211</link>
		<dc:creator>annon</dc:creator>
		<pubDate>Fri, 12 Aug 2011 00:39:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-14211</guid>
		<description>Hi
I&#039;ve come across your blog a few times and have found it very helpful.  So let me begin by thanking you.

I have a small question that I&#039;ve not been able to find the solution to online.  I&#039;m hoping you may be able to shed some light on the matter.

The following structure has 2 elements.

&lt;pre&gt;
people = struct(...
&#039;name&#039;,{&#039;bob&#039;, &#039;john&#039;},...
&#039;numKids&#039;,{0, 2}, ...
&#039;kidsage&#039;,{[],[12,9]});
&lt;/pre&gt;
each element people(1), people(2) has three frields (name, numKids, kidsage)

Instead of declaring the structure in one line as above, I would like to define it one field at a time.
The closest working example I&#039;ve been able to come up with is
&lt;pre&gt;
people = struct

people.(&#039;name&#039;) = {&#039;bob, &#039;john&#039;}
people.(&#039;numkids&#039;) = {0, 2}
people.(&#039;kidsage&#039;) = {[], [12, 9]}
&lt;/pre&gt;

But defined in this way, the people structure only has one element.
ie.
&lt;pre&gt;
people(1) =

name: {&#039;bob&#039; &#039;john&#039;}
numkids: {[0] [2]}
kidsage: {[] [12, 9]}
&lt;/pre&gt;

Any ideas?</description>
		<content:encoded><![CDATA[<p>Hi<br />
I&#8217;ve come across your blog a few times and have found it very helpful.  So let me begin by thanking you.</p>
<p>I have a small question that I&#8217;ve not been able to find the solution to online.  I&#8217;m hoping you may be able to shed some light on the matter.</p>
<p>The following structure has 2 elements.</p>
<pre>
people = struct(...
'name',{'bob', 'john'},...
'numKids',{0, 2}, ...
'kidsage',{[],[12,9]});
</pre>
<p>each element people(1), people(2) has three frields (name, numKids, kidsage)</p>
<p>Instead of declaring the structure in one line as above, I would like to define it one field at a time.<br />
The closest working example I&#8217;ve been able to come up with is</p>
<pre>
people = struct

people.('name') = {'bob, 'john'}
people.('numkids') = {0, 2}
people.('kidsage') = {[], [12, 9]}
</pre>
<p>But defined in this way, the people structure only has one element.<br />
ie.</p>
<pre>
people(1) =

name: {'bob' 'john'}
numkids: {[0] [2]}
kidsage: {[] [12, 9]}
</pre>
<p>Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Huw</title>
		<link>http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13551</link>
		<dc:creator>Huw</dc:creator>
		<pubDate>Fri, 14 May 2010 09:44:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13551</guid>
		<description>I also found the same problem with post 4 as described in post 7 and would be grateful if someone could explain why the solution needs to use 2 lines of code. e.g.

&lt;pre&gt;
weather = repmat(struct(&#039;temp&#039;, 72, &#039;rainfall&#039;, 0.0),1,3);
nums = [23 10 12];
cellArray = num2cell(nums - [weather(:).temp])
[weather(:).rainfall] = cellArray{:}
&lt;/pre&gt;

Is there no way to assign each element of the result of num2cell to weather.rainfall on a single line.</description>
		<content:encoded><![CDATA[<p>I also found the same problem with post 4 as described in post 7 and would be grateful if someone could explain why the solution needs to use 2 lines of code. e.g.</p>
<pre>
weather = repmat(struct('temp', 72, 'rainfall', 0.0),1,3);
nums = [23 10 12];
cellArray = num2cell(nums - [weather(:).temp])
[weather(:).rainfall] = cellArray{:}
</pre>
<p>Is there no way to assign each element of the result of num2cell to weather.rainfall on a single line.</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-13550</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 13 May 2010 18:20:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13550</guid>
		<description>@Emil,

Shy not just save it?  Why are you trying to pull them out of the structure?

Doug</description>
		<content:encoded><![CDATA[<p>@Emil,</p>
<p>Shy not just save it?  Why are you trying to pull them out of the structure?</p>
<p>Doug</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-13549</link>
		<dc:creator>Emil</dc:creator>
		<pubDate>Thu, 13 May 2010 12:00:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13549</guid>
		<description>Hei,

I ran into the same problem described by the previous two posts.

&lt;pre&gt;
names = {&#039;Peter&#039;,&#039;Paul&#039;,&#039;Mary&#039;};
ages = {25,29,26};
[people(1:3).name] = names{:};
[people(1:3).age] = ages{:};
&lt;/pre&gt;
Now
&lt;pre&gt;
save(&#039;test&#039;,&#039;-struct&#039;,&#039;people&#039;)
&lt;/pre&gt;
yields:
??? Error using ==&gt; save
The argument to -STRUCT must be the name of a scalar structure variable.

whereas
&lt;pre&gt;
person = people(1);
save(&#039;test&#039;,&#039;-struct&#039;,&#039;person&#039;)
&lt;/pre&gt;
is no problem.

The following would work
&lt;pre&gt;
save(&#039;test&#039;,&#039;people&#039;)
&lt;/pre&gt;
but is very unhandy as
&lt;pre&gt;
x = load(&#039;test&#039;);
&lt;/pre&gt;

makes x a 1x1 struct with field people, and would require additionally
&lt;pre&gt;
x = x.people;
&lt;/pre&gt;

So the question is:
What is the best way to save a struct array?

Emil

by the way, if ages was a 1x3 double [25,29,26] and not a 1x3 cell: 
How would I deal it across the struct array people? This is the same problem as adressed by Dan on Aug 4th</description>
		<content:encoded><![CDATA[<p>Hei,</p>
<p>I ran into the same problem described by the previous two posts.</p>
<pre>
names = {'Peter','Paul','Mary'};
ages = {25,29,26};
[people(1:3).name] = names{:};
[people(1:3).age] = ages{:};
</pre>
<p>Now</p>
<pre>
save('test','-struct','people')
</pre>
<p>yields:<br />
??? Error using ==&gt; save<br />
The argument to -STRUCT must be the name of a scalar structure variable.</p>
<p>whereas</p>
<pre>
person = people(1);
save('test','-struct','person')
</pre>
<p>is no problem.</p>
<p>The following would work</p>
<pre>
save('test','people')
</pre>
<p>but is very unhandy as</p>
<pre>
x = load('test');
</pre>
<p>makes x a 1&#215;1 struct with field people, and would require additionally</p>
<pre>
x = x.people;
</pre>
<p>So the question is:<br />
What is the best way to save a struct array?</p>
<p>Emil</p>
<p>by the way, if ages was a 1&#215;3 double [25,29,26] and not a 1&#215;3 cell:<br />
How would I deal it across the struct array people? This is the same problem as adressed by Dan on Aug 4th</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-13449</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 02 Mar 2010 18:03:42 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/pick/2008/04/22/matlab-basics-array-of-structures-vs-structures-of-arrays/#comment-13449</guid>
		<description>@hakdan,

I do not understand your question.  What have you tried?

Doug</description>
		<content:encoded><![CDATA[<p>@hakdan,</p>
<p>I do not understand your question.  What have you tried?</p>
<p>Doug</p>
]]></content:encoded>
	</item>
</channel>
</rss>

