<?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: Structures and Comma-Separated Lists</title>
	<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 &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62;. She writes here about once a week on MATLAB programming and related topics. &#60;br&#62;&#60;br&#62;&#60;a href="/images/loren-full.jpg"&#62;&#60;img src="/images/loren.jpg"&#62;&#60;/a&#62;</description>
	<pubDate>Sun, 22 Nov 2009 23:17:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30534</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 14 Aug 2009 21:11:56 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30534</guid>
		<description>Todd-

Last things first.  It would be great if you gave your suggestion via the link on the right of the blog.  In the meantime, you could make your own struct-like class that would ensure whatever characteristics you want.

As for the performance, what's happening is that in the original struct, all the fields share the same data.  And MATLAB is carefully keeping track of all the references.  When you save and then load it, they are each saved as separate arrays so no extra work (reference counting, etc.) needs to happen.  Is your test case where the fields share the same data really typical?  If not, try the same experiment replacing the repmat array with some random matrices.

--Loren</description>
		<content:encoded><![CDATA[<p>Todd-</p>
<p>Last things first.  It would be great if you gave your suggestion via the link on the right of the blog.  In the meantime, you could make your own struct-like class that would ensure whatever characteristics you want.</p>
<p>As for the performance, what&#8217;s happening is that in the original struct, all the fields share the same data.  And MATLAB is carefully keeping track of all the references.  When you save and then load it, they are each saved as separate arrays so no extra work (reference counting, etc.) needs to happen.  Is your test case where the fields share the same data really typical?  If not, try the same experiment replacing the repmat array with some random matrices.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30532</link>
		<dc:creator>Todd</dc:creator>
		<pubDate>Fri, 14 Aug 2009 19:02:23 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30532</guid>
		<description>Something weird about [s.field] concatenation: if a large structure array is created using repmat, the above operation is extremely slow. However if one saves the same structure array to a mat file and reloads it, the above [s.field] syntax is ~400X faster. 

&lt;pre&gt;
s=repmat(struct('a',0),5e4,1);
tic;t=[s.a];toc

save s s
clear all
load s
tic;t=[s.a];toc

&lt;/pre&gt;
The [s.a] command takes ~30 seconds on my XP32 system and ~90sec on my XP64 system.

I wrote a simple function in place of the built-in cat:

&lt;pre&gt;
function out = fcopy(in,fname)
out = repmat(in(1).(fname),size(in));
for i=1:numel(in)
    out(i) = in(i).(fname);
end
&lt;/pre&gt;

Like others above, I also would like to have a homogenous structure array where all structure elements are identical, as in C. It would certainly be more EML-compliant than Matlab's current heterogenous structure array. I assume we would then be able to access substructures directly. In Erik's example above, I would hope that [s.px(1)] would work for a homogenous structure. I currently have to copy out fields before I can access elements of them: spx = vertcat(s.px), spx(:,1)</description>
		<content:encoded><![CDATA[<p>Something weird about [s.field] concatenation: if a large structure array is created using repmat, the above operation is extremely slow. However if one saves the same structure array to a mat file and reloads it, the above [s.field] syntax is ~400X faster. </p>
<pre>
s=repmat(struct('a',0),5e4,1);
tic;t=[s.a];toc

save s s
clear all
load s
tic;t=[s.a];toc
</pre>
<p>The [s.a] command takes ~30 seconds on my XP32 system and ~90sec on my XP64 system.</p>
<p>I wrote a simple function in place of the built-in cat:</p>
<pre>
function out = fcopy(in,fname)
out = repmat(in(1).(fname),size(in));
for i=1:numel(in)
    out(i) = in(i).(fname);
end
</pre>
<p>Like others above, I also would like to have a homogenous structure array where all structure elements are identical, as in C. It would certainly be more EML-compliant than Matlab&#8217;s current heterogenous structure array. I assume we would then be able to access substructures directly. In Erik&#8217;s example above, I would hope that [s.px(1)] would work for a homogenous structure. I currently have to copy out fields before I can access elements of them: spx = vertcat(s.px), spx(:,1)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30442</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 02 Jul 2009 13:21:45 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30442</guid>
		<description>Mic-

who can help you find the variable names.

&lt;pre&gt;
varnames = who
&lt;/pre&gt;

inputname will return an empty for temporary variables that are passed (e.g., x(3))

You may be better off constructing an array of the names and passing that in as well.

--Loren</description>
		<content:encoded><![CDATA[<p>Mic-</p>
<p>who can help you find the variable names.</p>
<pre>
varnames = who
</pre>
<p>inputname will return an empty for temporary variables that are passed (e.g., x(3))</p>
<p>You may be better off constructing an array of the names and passing that in as well.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mic</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30441</link>
		<dc:creator>mic</dc:creator>
		<pubDate>Thu, 02 Jul 2009 13:03:46 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30441</guid>
		<description>i have finally created general function for all users !
it creates structure very easily now !!!
================
function [theStruct]  = createStruct(varargin)

n=nargin;
theStruct = struct;

for ind=1:nargin
   theStruct =  setfield(theStruct,inputname(ind),varargin{ind});
end
=========================
examples :

a=1;
b=2;
thestruct=createStruct(a,b)
 theStruct

theStruct = 

    a: 1
    b: 2
---------------------
c=3
d=[ 1 2 3]
e= [ 1 2; 3 4]
thestruct=createStruct(a,b,d,e)
thestruct = 

    a: 1
    b: 2
    d: [1 2 3]
    e: [2x2 double]</description>
		<content:encoded><![CDATA[<p>i have finally created general function for all users !<br />
it creates structure very easily now !!!<br />
================<br />
function [theStruct]  = createStruct(varargin)</p>
<p>n=nargin;<br />
theStruct = struct;</p>
<p>for ind=1:nargin<br />
   theStruct =  setfield(theStruct,inputname(ind),varargin{ind});<br />
end<br />
=========================<br />
examples :</p>
<p>a=1;<br />
b=2;<br />
thestruct=createStruct(a,b)<br />
 theStruct</p>
<p>theStruct = </p>
<p>    a: 1<br />
    b: 2<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
c=3<br />
d=[ 1 2 3]<br />
e= [ 1 2; 3 4]<br />
thestruct=createStruct(a,b,d,e)<br />
thestruct = </p>
<p>    a: 1<br />
    b: 2<br />
    d: [1 2 3]<br />
    e: [2&#215;2 double]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30435</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 02 Jul 2009 10:48:36 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30435</guid>
		<description>Mic-

Look at the help for the function struct.

--Loren</description>
		<content:encoded><![CDATA[<p>Mic-</p>
<p>Look at the help for the function struct.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mic</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30434</link>
		<dc:creator>mic</dc:creator>
		<pubDate>Thu, 02 Jul 2009 08:39:06 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-30434</guid>
		<description>i want to create structure from several variables ..
each time i have diffrent number of variables and diffrent types
lets say
x1  240*240  matrix
x2  3.132
x3  [ 1 2 3]

mystruct   =funct(x1,x2,x3)
will be 

mystruct.x1 
mystruct.x2
mystruct.x3

and if 
mystruct   =funct(x1,x3)
will be
mystruct.x1 
mystruct.x3

how i can create such dynamic struct?</description>
		<content:encoded><![CDATA[<p>i want to create structure from several variables ..<br />
each time i have diffrent number of variables and diffrent types<br />
lets say<br />
x1  240*240  matrix<br />
x2  3.132<br />
x3  [ 1 2 3]</p>
<p>mystruct   =funct(x1,x2,x3)<br />
will be </p>
<p>mystruct.x1<br />
mystruct.x2<br />
mystruct.x3</p>
<p>and if<br />
mystruct   =funct(x1,x3)<br />
will be<br />
mystruct.x1<br />
mystruct.x3</p>
<p>how i can create such dynamic struct?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-28151</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 04 Apr 2008 16:38:25 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-28151</guid>
		<description>Ljubomir-

No, you need to know if it's a cell array or not to use the string appropriately.  You are doing it correctly.

--Loren</description>
		<content:encoded><![CDATA[<p>Ljubomir-</p>
<p>No, you need to know if it&#8217;s a cell array or not to use the string appropriately.  You are doing it correctly.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ljubomir Josifovski</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-28150</link>
		<dc:creator>Ljubomir Josifovski</dc:creator>
		<pubDate>Fri, 04 Apr 2008 15:27:27 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-28150</guid>
		<description>I often want to just go through a list of constants, as if

&#62;&#62; for a = {'b', 'c'}, a, end
a = 
    'b'
a = 
    'c'

but then get an error when using 'a' as it is actually a cell

&#62;&#62; whos a
  Name      Size            Bytes  Class    Attributes
  a         1x1                62  cell  

Ie one has to a{1} to get to the contents.

Is there maybe a better way to traverse a strings list?

Thanks,</description>
		<content:encoded><![CDATA[<p>I often want to just go through a list of constants, as if</p>
<p>&gt;&gt; for a = {&#8217;b', &#8216;c&#8217;}, a, end<br />
a =<br />
    &#8216;b&#8217;<br />
a =<br />
    &#8216;c&#8217;</p>
<p>but then get an error when using &#8216;a&#8217; as it is actually a cell</p>
<p>&gt;&gt; whos a<br />
  Name      Size            Bytes  Class    Attributes<br />
  a         1&#215;1                62  cell  </p>
<p>Ie one has to a{1} to get to the contents.</p>
<p>Is there maybe a better way to traverse a strings list?</p>
<p>Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vidya</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-16456</link>
		<dc:creator>Vidya</dc:creator>
		<pubDate>Fri, 31 Aug 2007 17:20:44 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-16456</guid>
		<description>I would like to know how to 'create subsystem' using scripts. Any hints would be appreciated.

Also, when I select multiple blocks, how can I access them?

Thanks</description>
		<content:encoded><![CDATA[<p>I would like to know how to &#8216;create subsystem&#8217; using scripts. Any hints would be appreciated.</p>
<p>Also, when I select multiple blocks, how can I access them?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexa</title>
		<link>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-16420</link>
		<dc:creator>Alexa</dc:creator>
		<pubDate>Thu, 30 Aug 2007 08:12:50 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/02/structures-and-comma-separated-lists/#comment-16420</guid>
		<description>.......</description>
		<content:encoded><![CDATA[<p>&#8230;&#8230;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
