<?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: Working with Arrays of Structures</title>
	<atom:link href="http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/</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: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-32920</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Wed, 18 Jan 2012 22:29:57 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-32920</guid>
		<description>Darin-

I am not sure.  I would recommend contacting support and reporting the behavior as a bug, which it seems like to me.  But if I heard a reason that made sense, I might be swayed the other way.

--Loren</description>
		<content:encoded><![CDATA[<p>Darin-</p>
<p>I am not sure.  I would recommend contacting support and reporting the behavior as a bug, which it seems like to me.  But if I heard a reason that made sense, I might be swayed the other way.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darin</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-32917</link>
		<dc:creator>Darin</dc:creator>
		<pubDate>Wed, 18 Jan 2012 19:17:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-32917</guid>
		<description>Hi Loren,

I get you on how struct array references like, temp(3:5).A, return coma lists... and, like you, don&#039;t get the various confusions this seems to cause.

But I&#039;m trying to understand an inconsistency (BUG?) in this behavior:

[temp(false)] = nan    or [temp(4:3)] = nan

correctly, does nothing when temp is a regular array, BUT when temp is a structure containing a field &quot;A&quot;:

[temp(false).A] = nan or [temp(4:3).A] = nan

(Which looks look me like an IDENTICAL case given, the comma list interpretation)

gives an error about &quot;too many elements&quot; on the right side.

Is there a rational reason for this inconsistency that you can help me follow... or is it a BUG?  It certainly complicates code to special-handle the null case.

Or, am I missing a shortcut there?

Thanks,
Darin</description>
		<content:encoded><![CDATA[<p>Hi Loren,</p>
<p>I get you on how struct array references like, temp(3:5).A, return coma lists&#8230; and, like you, don&#8217;t get the various confusions this seems to cause.</p>
<p>But I&#8217;m trying to understand an inconsistency (BUG?) in this behavior:</p>
<p>[temp(false)] = nan    or [temp(4:3)] = nan</p>
<p>correctly, does nothing when temp is a regular array, BUT when temp is a structure containing a field &#8220;A&#8221;:</p>
<p>[temp(false).A] = nan or [temp(4:3).A] = nan</p>
<p>(Which looks look me like an IDENTICAL case given, the comma list interpretation)</p>
<p>gives an error about &#8220;too many elements&#8221; on the right side.</p>
<p>Is there a rational reason for this inconsistency that you can help me follow&#8230; or is it a BUG?  It certainly complicates code to special-handle the null case.</p>
<p>Or, am I missing a shortcut there?</p>
<p>Thanks,<br />
Darin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-32688</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 18 Nov 2011 13:53:22 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-32688</guid>
		<description>Anna-

What code have you tried?

--Loren</description>
		<content:encoded><![CDATA[<p>Anna-</p>
<p>What code have you tried?</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anna</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-32684</link>
		<dc:creator>Anna</dc:creator>
		<pubDate>Fri, 18 Nov 2011 12:21:24 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-32684</guid>
		<description>Sorry here is the code.....

&lt;pre&gt;
A = [1 2 3; 1 2 4]

f(1).h = [1 2 5; 2 5 6; 1 2 3; 3 5 6]
f(2).h = [1 2 6; 3 5 6; 1 5 3; 3 5 6]
f(3).h = [1 2 4; 3 4 5; 1 1 3; 3 4 6]

[m,n] = arrayfun(@(x)find(x.h==A),f,&#039;uniformoutput&#039;,false)
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Sorry here is the code&#8230;..</p>
<pre>
A = [1 2 3; 1 2 4]

f(1).h = [1 2 5; 2 5 6; 1 2 3; 3 5 6]
f(2).h = [1 2 6; 3 5 6; 1 5 3; 3 5 6]
f(3).h = [1 2 4; 3 4 5; 1 1 3; 3 4 6]

[m,n] = arrayfun(@(x)find(x.h==A),f,'uniformoutput',false)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anna</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-32683</link>
		<dc:creator>Anna</dc:creator>
		<pubDate>Fri, 18 Nov 2011 12:17:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-32683</guid>
		<description>Hi Loren, 

Can you tell me how to use the arrayfun to locate values that match entire rows in data. 

i.e. 
&lt;A&gt;






If I do this, then I get....
??? Error using ==&gt; eq
Matrix dimensions must agree.

Error in ==&gt; @(x)find(x.h==A)

Thanks,

Anna</description>
		<content:encoded><![CDATA[<p>Hi Loren, </p>
<p>Can you tell me how to use the arrayfun to locate values that match entire rows in data. </p>
<p>i.e.<br />
<a></a></p>
<p>If I do this, then I get&#8230;.<br />
??? Error using ==&gt; eq<br />
Matrix dimensions must agree.</p>
<p>Error in ==&gt; @(x)find(x.h==A)</p>
<p>Thanks,</p>
<p>Anna</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-32559</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 21 Oct 2011 13:28:18 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-32559</guid>
		<description>HH,

Thanks for sharing your thoughts.  I have made sure they got into the bug/enhancement list.

--Loren</description>
		<content:encoded><![CDATA[<p>HH,</p>
<p>Thanks for sharing your thoughts.  I have made sure they got into the bug/enhancement list.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HH</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-32557</link>
		<dc:creator>HH</dc:creator>
		<pubDate>Thu, 20 Oct 2011 13:51:50 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-32557</guid>
		<description>Loren, 

struct arrays seem very unwieldy, they are hard to create via preallocation, and seem impossible to merge without looping, e.g. if you have a struct array O where O(i) is combination of the two structs a and b, then there is little hope of creating O(i) = mergestruct(a,b) (substitute for mergestruct your favourite vertcat function for structs here).

It would be great if mathworks provided some more tools for struct arrays, a separate class name, detection via is* functions, and vertcat methods, easier syntax for creating (preallocation especially), etc. 

Best, HH</description>
		<content:encoded><![CDATA[<p>Loren, </p>
<p>struct arrays seem very unwieldy, they are hard to create via preallocation, and seem impossible to merge without looping, e.g. if you have a struct array O where O(i) is combination of the two structs a and b, then there is little hope of creating O(i) = mergestruct(a,b) (substitute for mergestruct your favourite vertcat function for structs here).</p>
<p>It would be great if mathworks provided some more tools for struct arrays, a separate class name, detection via is* functions, and vertcat methods, easier syntax for creating (preallocation especially), etc. </p>
<p>Best, HH</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-31743</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 11 Oct 2010 18:34:22 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-31743</guid>
		<description>Miguel-

How large is f?  I wonder if the code would be clearer if you wrote the for-loop.

One way is to convert the struct to a cell and work on each cell. Then convert back to a struct.  Not sure this is worth the effort however.

Others?
--loren</description>
		<content:encoded><![CDATA[<p>Miguel-</p>
<p>How large is f?  I wonder if the code would be clearer if you wrote the for-loop.</p>
<p>One way is to convert the struct to a cell and work on each cell. Then convert back to a struct.  Not sure this is worth the effort however.</p>
<p>Others?<br />
&#8211;loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miguel</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-31742</link>
		<dc:creator>Miguel</dc:creator>
		<pubDate>Mon, 11 Oct 2010 18:09:56 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-31742</guid>
		<description>Hi Loren

I am beginning to learn Matlab and I have a question related to this post. Using your example, if i wanted to, first, find certain values in a struct and then replace them by another value, say 0. So the first thing would be like this:
&lt;pre&gt;
f(1).h = [1 2 3 4];
f(2).h = [5 6 3 8];
[m,n] = arrayfun(@(x)find(x.h==3),f,&#039;uniformoutput&#039;,false)
&lt;/pre&gt;
Now that i have the indexes, how can I replace those &quot;3&quot; by, for example, 0? I mean without using loops. Thanks a lot in advance.</description>
		<content:encoded><![CDATA[<p>Hi Loren</p>
<p>I am beginning to learn Matlab and I have a question related to this post. Using your example, if i wanted to, first, find certain values in a struct and then replace them by another value, say 0. So the first thing would be like this:</p>
<pre>
f(1).h = [1 2 3 4];
f(2).h = [5 6 3 8];
[m,n] = arrayfun(@(x)find(x.h==3),f,'uniformoutput',false)
</pre>
<p>Now that i have the indexes, how can I replace those &#8220;3&#8243; by, for example, 0? I mean without using loops. Thanks a lot in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/11/24/working-with-arrays-of-structures/#comment-31560</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 04 Aug 2010 13:55:19 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=67#comment-31560</guid>
		<description>Emil-

struct2cell should get you part of the way there - but not the data not arranged as a struct per se.  You can use a for loop.  Or cellfun (which effectively has a loop inside it).  

--Loren</description>
		<content:encoded><![CDATA[<p>Emil-</p>
<p>struct2cell should get you part of the way there &#8211; but not the data not arranged as a struct per se.  You can use a for loop.  Or cellfun (which effectively has a loop inside it).  </p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

