<?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 for Loren on the Art of MATLAB</title>
	<link>http://blogs.mathworks.com/loren</link>
	<description>Loren Shure  works on design of the MATLAB language at The MathWorks. She writes here about once a week on MATLAB programming and related topics. </description>
	<pubDate>Wed, 14 May 2008 00:52:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>Comment on Cell Arrays and Their Contents by Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/#comment-29026</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 13 May 2008 18:18:24 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/#comment-29026</guid>
		<description>Katie-

You probably need to consider using unique or ismember when deciding to put an array into a cell.  You might get some ideas from looking at the code in 
&lt;a href="http://blogs.mathworks.com/loren/2006/02/08/use-nested-functions-to-memoize-costly-functions/" rel="nofollow"&gt;  this post&lt;/a&gt;.

--Loren</description>
		<content:encoded><![CDATA[<p>Katie-</p>
<p>You probably need to consider using unique or ismember when deciding to put an array into a cell.  You might get some ideas from looking at the code in<br />
<a href="http://blogs.mathworks.com/loren/2006/02/08/use-nested-functions-to-memoize-costly-functions/" rel="nofollow">  this post</a>.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Making Pretty Graphs by Andrew</title>
		<link>http://blogs.mathworks.com/loren/2007/12/11/making-pretty-graphs/#comment-29025</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Tue, 13 May 2008 18:13:09 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/12/11/making-pretty-graphs/#comment-29025</guid>
		<description>Hi there,
It is time to write my thesis and I am having some difficulty exporting my figures in the way I want. First, I am using pdflatex and hence cannot use psfrag or the equivalent to alter the font of the axes labels etc in my Matlab figures. The Matlab export set-up does a nice job, converting everything to a given font, but I cannot get the computer modern fonts (the default font of latex) 'cmr' to work in the export set-up. Simply nothing happens as though it does not support the font. However, in the figure editor the 'cmr' fonts work so it does not seem to be the case that Matlab simply doesn't support computer modern fonts. Any ideas ?</description>
		<content:encoded><![CDATA[<p>Hi there,<br />
It is time to write my thesis and I am having some difficulty exporting my figures in the way I want. First, I am using pdflatex and hence cannot use psfrag or the equivalent to alter the font of the axes labels etc in my Matlab figures. The Matlab export set-up does a nice job, converting everything to a given font, but I cannot get the computer modern fonts (the default font of latex) &#8216;cmr&#8217; to work in the export set-up. Simply nothing happens as though it does not support the font. However, in the figure editor the &#8216;cmr&#8217; fonts work so it does not seem to be the case that Matlab simply doesn&#8217;t support computer modern fonts. Any ideas ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Cell Arrays and Their Contents by Katie</title>
		<link>http://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/#comment-29019</link>
		<dc:creator>Katie</dc:creator>
		<pubDate>Tue, 13 May 2008 17:22:16 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/#comment-29019</guid>
		<description>I have created a large cell that holds sign patterns for 4x4 matrices. The matrices stored in the cell are generated by a loop. Is there a way to tell the loop to store only new matrices that are unique and to discard repeated ones? 
this is what i have so far: 
A=cell (10,10) %for now the size is arbitrary
 for i=1:10 j=1:10
a=-2;b=2  %create range from -M to M
v=a+(b-a)*rand(4,1)  %create 2 random vectors
w=a+(b-a)*rand(1,4)
P=eye(4,4)+v*w  %create random matrix P
J=gallery('jordbloc',4,0)  %create nilpotent matrix 
A1=P*J*inv(P)  
ans=(A1&#62;0)
A(i,j)={ans}
end

thank yoU!!!!</description>
		<content:encoded><![CDATA[<p>I have created a large cell that holds sign patterns for 4&#215;4 matrices. The matrices stored in the cell are generated by a loop. Is there a way to tell the loop to store only new matrices that are unique and to discard repeated ones?<br />
this is what i have so far:<br />
A=cell (10,10) %for now the size is arbitrary<br />
 for i=1:10 j=1:10<br />
a=-2;b=2  %create range from -M to M<br />
v=a+(b-a)*rand(4,1)  %create 2 random vectors<br />
w=a+(b-a)*rand(1,4)<br />
P=eye(4,4)+v*w  %create random matrix P<br />
J=gallery(&#8217;jordbloc&#8217;,4,0)  %create nilpotent matrix<br />
A1=P*J*inv(P)<br />
ans=(A1&gt;0)<br />
A(i,j)={ans}<br />
end</p>
<p>thank yoU!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multiple Outputs by Brad Phelan</title>
		<link>http://blogs.mathworks.com/loren/2007/01/31/multiple-outputs/#comment-28962</link>
		<dc:creator>Brad Phelan</dc:creator>
		<pubDate>Mon, 12 May 2008 19:13:20 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/01/31/multiple-outputs/#comment-28962</guid>
		<description>Hi Tim,

I understand where you are coming from. It is my one pet annoyance with Matlab, the lack of multi line anonymous functions. Practically every one of Loren's blog posts covers a topic that could be more elegantly solved with such a capability. However I don't think you are going to see the capability in the language anytime soon.

You may be interested in this however. In 2005 I wrote a text generator for Matlab. It is a tool that falls into the same category of text templating tools such as PHP(php), JSP(java), ERUBY(ruby), CHEETAH(python) etc. Essentially you embed bits of Matlab code into a text file to generate more complicated text. Generally that is all irrelevant to this thread but to make the text generation more powerful I implemented multi line anonymous functions by transparently translating every multi line anonymous function into a named nested function.

http://xtargets.com/cms/Tutorials/Matlab-Programming/MTemplate-Matlab-Code-Generation-and-Text-Templating.html

The section "ADVANCED TEMPLATE PROGRAMMING" gives details on this feature.

The point being is that this feature is simple to add to Matlab as it is just a trivial translation into language features that already exist.

A quick example from the download package

An example input file
http://pastie.caboo.se/pastes/195636

and an example output file
http://pastie.caboo.se/pastes/195637

Note that BLOCK_FUN_1 and BLOCK_FUN_2 are automatically generated nested functions arising from the anonymous functions at line 17 and 21 in the input file [http://pastie.caboo.se/195636 ]

It was quite a lot of fun writing this tool. Essentially a small compiler project. The compiler could be modified to translate normal matlab code ( instead of text template code ) with multi line anonymous functions into standard Matlab. Feel free to give it a go.


Cheers

B</description>
		<content:encoded><![CDATA[<p>Hi Tim,</p>
<p>I understand where you are coming from. It is my one pet annoyance with Matlab, the lack of multi line anonymous functions. Practically every one of Loren&#8217;s blog posts covers a topic that could be more elegantly solved with such a capability. However I don&#8217;t think you are going to see the capability in the language anytime soon.</p>
<p>You may be interested in this however. In 2005 I wrote a text generator for Matlab. It is a tool that falls into the same category of text templating tools such as PHP(php), JSP(java), ERUBY(ruby), CHEETAH(python) etc. Essentially you embed bits of Matlab code into a text file to generate more complicated text. Generally that is all irrelevant to this thread but to make the text generation more powerful I implemented multi line anonymous functions by transparently translating every multi line anonymous function into a named nested function.</p>
<p><a href="http://xtargets.com/cms/Tutorials/Matlab-Programming/MTemplate-Matlab-Code-Generation-and-Text-Templating.html" rel="nofollow">http://xtargets.com/cms/Tutorials/Matlab-Programming/MTemplate-Matlab-Code-Generation-and-Text-Templating.html</a></p>
<p>The section &#8220;ADVANCED TEMPLATE PROGRAMMING&#8221; gives details on this feature.</p>
<p>The point being is that this feature is simple to add to Matlab as it is just a trivial translation into language features that already exist.</p>
<p>A quick example from the download package</p>
<p>An example input file<br />
<a href="http://pastie.caboo.se/pastes/195636" rel="nofollow">http://pastie.caboo.se/pastes/195636</a></p>
<p>and an example output file<br />
<a href="http://pastie.caboo.se/pastes/195637" rel="nofollow">http://pastie.caboo.se/pastes/195637</a></p>
<p>Note that BLOCK_FUN_1 and BLOCK_FUN_2 are automatically generated nested functions arising from the anonymous functions at line 17 and 21 in the input file [http://pastie.caboo.se/195636 ]</p>
<p>It was quite a lot of fun writing this tool. Essentially a small compiler project. The compiler could be modified to translate normal matlab code ( instead of text template code ) with multi line anonymous functions into standard Matlab. Feel free to give it a go.</p>
<p>Cheers</p>
<p>B</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multiple Outputs by Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/01/31/multiple-outputs/#comment-28941</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sun, 11 May 2008 12:16:31 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/01/31/multiple-outputs/#comment-28941</guid>
		<description>Timothee-

Anonymous functions can only be a single (complicated) expression.  You might be able to do what you want using deal with anonymous functions:

&lt;pre&gt;
f = @(x,y,z) deal(fun(x,y),fun2(x,z), fun3(x,y,z));
&lt;/pre&gt;

That assumes that none of the calculations depends on the others in the expressions you provide.  Another similar idea is to concatenate results:

&lt;pre&gt;
f = @(x,y,z) [fun(x,y), fun2(x,z), fun3(x,y,z)];
&lt;/pre&gt;

The first version produces multiple outputs, the second a single vector output.

--Loren</description>
		<content:encoded><![CDATA[<p>Timothee-</p>
<p>Anonymous functions can only be a single (complicated) expression.  You might be able to do what you want using deal with anonymous functions:</p>
<pre>
f = @(x,y,z) deal(fun(x,y),fun2(x,z), fun3(x,y,z));
</pre>
<p>That assumes that none of the calculations depends on the others in the expressions you provide.  Another similar idea is to concatenate results:</p>
<pre>
f = @(x,y,z) [fun(x,y), fun2(x,z), fun3(x,y,z)];
</pre>
<p>The first version produces multiple outputs, the second a single vector output.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Multiple Outputs by Timothee</title>
		<link>http://blogs.mathworks.com/loren/2007/01/31/multiple-outputs/#comment-28938</link>
		<dc:creator>Timothee</dc:creator>
		<pubDate>Sun, 11 May 2008 06:11:35 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/01/31/multiple-outputs/#comment-28938</guid>
		<description>Is there a way to combine multiple commands in anonymous functions?
ex1:
fun=@(A)([V,D]=eig(A); A*V-V*D)
ex2: more generally:
fun=@(A)([a,b]=my_fun1(A);[c,d]=my_fun2(a,b); my_fun3(a,b,c,d))
this doesn't work, although I don't see why it is not supported.
if there is no GENERAL workaround (cf post 15 is not very general), this would be one of the most useful features to include in matlab. This would avoid having to write lots of small functions, especially for development phase</description>
		<content:encoded><![CDATA[<p>Is there a way to combine multiple commands in anonymous functions?<br />
ex1:<br />
fun=@(A)([V,D]=eig(A); A*V-V*D)<br />
ex2: more generally:<br />
fun=@(A)([a,b]=my_fun1(A);[c,d]=my_fun2(a,b); my_fun3(a,b,c,d))<br />
this doesn&#8217;t work, although I don&#8217;t see why it is not supported.<br />
if there is no GENERAL workaround (cf post 15 is not very general), this would be one of the most useful features to include in matlab. This would avoid having to write lots of small functions, especially for development phase</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Creating Sparse Finite-Element Matrices in MATLAB by Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/#comment-28884</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 07 May 2008 14:02:26 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/#comment-28884</guid>
		<description>Here's Cleve's reply to Etienne:

The crucial factor is the number and location of the nonzero elements in the LU factors, not in the original matrices.  This doesn't show us the original matrices.  "Numerically the same" apparently means the difference is small.  That's not enough.  The magnitude of the nonzeros is irrelevant; it's their existence that matters.
  -- Cleve</description>
		<content:encoded><![CDATA[<p>Here&#8217;s Cleve&#8217;s reply to Etienne:</p>
<p>The crucial factor is the number and location of the nonzero elements in the LU factors, not in the original matrices.  This doesn&#8217;t show us the original matrices.  &#8220;Numerically the same&#8221; apparently means the difference is small.  That&#8217;s not enough.  The magnitude of the nonzeros is irrelevant; it&#8217;s their existence that matters.<br />
  &#8212; Cleve</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Nested Functions and Variable Scope by Loren</title>
		<link>http://blogs.mathworks.com/loren/2008/01/16/nested-functions-and-variable-scope/#comment-28873</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 07 May 2008 11:13:17 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/01/16/nested-functions-and-variable-scope/#comment-28873</guid>
		<description>Tristan-

Nested functions can be slower in some cases currently.  We know we have some opportunities to optimize more.  However, be very careful as it depends on how many variables, how much data there is, how much data changes, etc.  I don't think one experiment characterizes the larger picture fully.

--Loren</description>
		<content:encoded><![CDATA[<p>Tristan-</p>
<p>Nested functions can be slower in some cases currently.  We know we have some opportunities to optimize more.  However, be very careful as it depends on how many variables, how much data there is, how much data changes, etc.  I don&#8217;t think one experiment characterizes the larger picture fully.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Nested Functions and Variable Scope by Tristan</title>
		<link>http://blogs.mathworks.com/loren/2008/01/16/nested-functions-and-variable-scope/#comment-28828</link>
		<dc:creator>Tristan</dc:creator>
		<pubDate>Tue, 06 May 2008 22:28:01 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/01/16/nested-functions-and-variable-scope/#comment-28828</guid>
		<description>Wow!
I just tried with a global variable and it's 5 times slower than with a argument!

function Untitled1

global x
x=ones(10,10);
tic
for i=1:1000000
    tsqr;
end
toc
end


function tsqr
global x
a=(x+1)./x;
end

Result : "Elapsed time is 11.449752 seconds."</description>
		<content:encoded><![CDATA[<p>Wow!<br />
I just tried with a global variable and it&#8217;s 5 times slower than with a argument!</p>
<p>function Untitled1</p>
<p>global x<br />
x=ones(10,10);<br />
tic<br />
for i=1:1000000<br />
    tsqr;<br />
end<br />
toc<br />
end</p>
<p>function tsqr<br />
global x<br />
a=(x+1)./x;<br />
end</p>
<p>Result : &#8220;Elapsed time is 11.449752 seconds.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Vectorizing Access to an Array of Structures by Jon</title>
		<link>http://blogs.mathworks.com/loren/2007/04/19/vectorizing-access-to-an-array-of-structures/#comment-28827</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Tue, 06 May 2008 22:14:37 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2007/04/19/vectorizing-access-to-an-array-of-structures/#comment-28827</guid>
		<description>Loren,

I encountered this same problem and I attempted to find the answer by looking at the documentation for struct.  In the documentation, example three is describing this very use of the struct but does not mention how to make the array.

This example in the documentation seems like an excellent place to mention how to get the arrays with the square brackets.

-Jon

From the documentation:
========================================================
========================================================
Example 3This example initializes one field f1 using a cell
array, and the other f2 using a scalar value:s = struct('f1', {1 3; 2 4}, 'f2', 25)
s = 
2x2 struct array with fields:
    f1
    f2Field f1 in each element of s is
assigned the corresponding value from the cell array {1 3; 2 4}:s.f1
ans =
     1
ans =
     2
ans =
     3
ans =
     4Field f2 for all elements of s is
assigned one common value because the values input for
this field was specified as a scalar:s.f2
ans =
    25
ans =
    25
ans =
    25
ans =
    25
========================================================
========================================================</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>I encountered this same problem and I attempted to find the answer by looking at the documentation for struct.  In the documentation, example three is describing this very use of the struct but does not mention how to make the array.</p>
<p>This example in the documentation seems like an excellent place to mention how to get the arrays with the square brackets.</p>
<p>-Jon</p>
<p>From the documentation:<br />
========================================================<br />
========================================================<br />
Example 3This example initializes one field f1 using a cell<br />
array, and the other f2 using a scalar value:s = struct(&#8217;f1&#8242;, {1 3; 2 4}, &#8216;f2&#8242;, 25)<br />
s =<br />
2&#215;2 struct array with fields:<br />
    f1<br />
    f2Field f1 in each element of s is<br />
assigned the corresponding value from the cell array {1 3; 2 4}:s.f1<br />
ans =<br />
     1<br />
ans =<br />
     2<br />
ans =<br />
     3<br />
ans =<br />
     4Field f2 for all elements of s is<br />
assigned one common value because the values input for<br />
this field was specified as a scalar:s.f2<br />
ans =<br />
    25<br />
ans =<br />
    25<br />
ans =<br />
    25<br />
ans =<br />
    25<br />
========================================================<br />
========================================================</p>
]]></content:encoded>
	</item>
</channel>
</rss>
