<?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: Beginner Woes</title>
	<atom:link href="http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/</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>Thu, 09 Feb 2012 04:19:21 +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</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-31967</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sun, 16 Jan 2011 11:24:55 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-31967</guid>
		<description>Gunay-

It will probably depend on how big b is (and what it is - your code doesn&#039;t run as you wrote it above).  If your replicated vector makes too large a matrix, you might look into whether a sparse diagonal matrix will work better for you.  And perhaps also bsxfun, but I can&#039;t think of how that would work exactly, esp. since I don&#039;t have MATLAB nearby.

--loren</description>
		<content:encoded><![CDATA[<p>Gunay-</p>
<p>It will probably depend on how big b is (and what it is &#8211; your code doesn&#8217;t run as you wrote it above).  If your replicated vector makes too large a matrix, you might look into whether a sparse diagonal matrix will work better for you.  And perhaps also bsxfun, but I can&#8217;t think of how that would work exactly, esp. since I don&#8217;t have MATLAB nearby.</p>
<p>&#8211;loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gunay</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-31966</link>
		<dc:creator>Gunay</dc:creator>
		<pubDate>Sat, 15 Jan 2011 14:58:54 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-31966</guid>
		<description>Hi,
I have a matrix where each column is a set of data. I would like multiple each column element by element with a vector. Is  the following the most efficient way?

&lt;pre&gt;
myMatrix = magic(3)
myVector = [1 2 3]&#039;
repVector = repmat(b,1,3)
myOutput = myMatrix.*repVector
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I have a matrix where each column is a set of data. I would like multiple each column element by element with a vector. Is  the following the most efficient way?</p>
<pre>
myMatrix = magic(3)
myVector = [1 2 3]'
repVector = repmat(b,1,3)
myOutput = myMatrix.*repVector
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-31099</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sun, 21 Feb 2010 11:54:29 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-31099</guid>
		<description>Antony-

You say &quot;the data comes out in various columns and not awlays the number of ones I specified with %f&quot;.  That&#039;s because the fprintf command is vectorized and repeats the format if the data you present are larger.  You need to make sure the format is an exact multiple of the number of elements/row (and that that is a fixed number) for your data.

--Loren</description>
		<content:encoded><![CDATA[<p>Antony-</p>
<p>You say &#8220;the data comes out in various columns and not awlays the number of ones I specified with %f&#8221;.  That&#8217;s because the fprintf command is vectorized and repeats the format if the data you present are larger.  You need to make sure the format is an exact multiple of the number of elements/row (and that that is a fixed number) for your data.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antony Drew</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-31097</link>
		<dc:creator>Antony Drew</dc:creator>
		<pubDate>Sat, 20 Feb 2010 03:05:13 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-31097</guid>
		<description>Hi Loren,

I have some data in a 3D matrix.  Specifically, I have 100 layers of a [90 column by 100 row] rectangle.  When I click inside the Array Editor, it always &quot;wraps&quot; the columns onto subsequent rows instead of preseting the data in neat grids which I could then paste into Excel.  Also, when I try to use the code: fprintf(fid,&#039;%7.4f  %7.4f  %7.4f %7.4f\n&#039;,PortWts), the data comes out in various columns and not awlays the number of ones I specified with %f.  To sum up, what is the best way to export a complex matrix or array in order to preserve the neatness of grids so that I don&#039;t have to copy and paste and fix them in EXCEL?  Even the &#039;diary&#039; function exports the data in a wrapped column format.  I basically want the data to appear as nicely as it does in the Array Editor for a simple 2-D matrix or rectangle, but for subsequent layers of more complex data etc.  I use the student version by the way.  Please advise.

Tony</description>
		<content:encoded><![CDATA[<p>Hi Loren,</p>
<p>I have some data in a 3D matrix.  Specifically, I have 100 layers of a [90 column by 100 row] rectangle.  When I click inside the Array Editor, it always &#8220;wraps&#8221; the columns onto subsequent rows instead of preseting the data in neat grids which I could then paste into Excel.  Also, when I try to use the code: fprintf(fid,&#8217;%7.4f  %7.4f  %7.4f %7.4f\n&#8217;,PortWts), the data comes out in various columns and not awlays the number of ones I specified with %f.  To sum up, what is the best way to export a complex matrix or array in order to preserve the neatness of grids so that I don&#8217;t have to copy and paste and fix them in EXCEL?  Even the &#8216;diary&#8217; function exports the data in a wrapped column format.  I basically want the data to appear as nicely as it does in the Array Editor for a simple 2-D matrix or rectangle, but for subsequent layers of more complex data etc.  I use the student version by the way.  Please advise.</p>
<p>Tony</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joel MacAuslan</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-23393</link>
		<dc:creator>Joel MacAuslan</dc:creator>
		<pubDate>Mon, 17 Dec 2007 04:43:08 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-23393</guid>
		<description>Loren,
I do not argue whether .&#039; is a good notation for conjugating every element.  I only observe that MATLAB has adopted exactly that interpretation for the other dot-operators, without exception.  

And BTW, the fact that it would trivialize part of the operation -- the transpose but not the conjugation -- is harmless.  (You could make an even stronger case for the uselessness of dot-plus.  But it is harmless as an operator in its own right, and its semantics are consistent with what dot does to the other common operators.  So putting it in the language is probably a GOOD design choice, not merely a harmless one.)

Perhaps conjugate-transpose should not have been given the simple apostrophe notation.  But once it was, the meaning of .&#039; was really not open for negotiation.  The adopted usage introduced a completely avoidable inconsistency in the language, and was thus a mistake in language design.

FWIW, this is (IMO) not the worst of MATLAB&#039;s inconsistencies -- and yet MATLAB is far, far better than most common languages in its design.</description>
		<content:encoded><![CDATA[<p>Loren,<br />
I do not argue whether .&#8217; is a good notation for conjugating every element.  I only observe that MATLAB has adopted exactly that interpretation for the other dot-operators, without exception.  </p>
<p>And BTW, the fact that it would trivialize part of the operation &#8212; the transpose but not the conjugation &#8212; is harmless.  (You could make an even stronger case for the uselessness of dot-plus.  But it is harmless as an operator in its own right, and its semantics are consistent with what dot does to the other common operators.  So putting it in the language is probably a GOOD design choice, not merely a harmless one.)</p>
<p>Perhaps conjugate-transpose should not have been given the simple apostrophe notation.  But once it was, the meaning of .&#8217; was really not open for negotiation.  The adopted usage introduced a completely avoidable inconsistency in the language, and was thus a mistake in language design.</p>
<p>FWIW, this is (IMO) not the worst of MATLAB&#8217;s inconsistencies &#8212; and yet MATLAB is far, far better than most common languages in its design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Florian Brucker</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-16206</link>
		<dc:creator>Florian Brucker</dc:creator>
		<pubDate>Tue, 08 May 2007 19:15:59 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-16206</guid>
		<description>Took me some time to notice that log ~= log10. I somehow expected that the natural logarithm would be called ln.

About &quot;.&#039;&quot;: I think what Joel says does make sense. This &quot;like the operator, but applied element-by-element&quot; is how many people (including me) see the period operator. So if &#039; is conjugate transpose, .&#039; would conjugate the elements. Perhaps using &#039; for transpose only and &quot; for conjugate transpose would&#039;ve been clearer, but that&#039;s a question of personal taste IMO.</description>
		<content:encoded><![CDATA[<p>Took me some time to notice that log ~= log10. I somehow expected that the natural logarithm would be called ln.</p>
<p>About &#8220;.&#8217;&#8221;: I think what Joel says does make sense. This &#8220;like the operator, but applied element-by-element&#8221; is how many people (including me) see the period operator. So if &#8216; is conjugate transpose, .&#8217; would conjugate the elements. Perhaps using &#8216; for transpose only and &#8221; for conjugate transpose would&#8217;ve been clearer, but that&#8217;s a question of personal taste IMO.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-16176</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 11 Apr 2007 12:05:59 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-16176</guid>
		<description>Joel-

I understand what you are saying about dot meaning element-wise for the other operations, but what does element-wise transpose mean?  Transposing a scalar is the same scalar.  I don&#039;t see why .&#039; should then mean conjugate each element; that&#039;s what the function conj does.  So it&#039;s not clear to me that defining .&#039; the way you suggest would have been useful and not confusing.

--Loren</description>
		<content:encoded><![CDATA[<p>Joel-</p>
<p>I understand what you are saying about dot meaning element-wise for the other operations, but what does element-wise transpose mean?  Transposing a scalar is the same scalar.  I don&#8217;t see why .&#8217; should then mean conjugate each element; that&#8217;s what the function conj does.  So it&#8217;s not clear to me that defining .&#8217; the way you suggest would have been useful and not confusing.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joel MacAuslan</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-16175</link>
		<dc:creator>Joel MacAuslan</dc:creator>
		<pubDate>Tue, 10 Apr 2007 18:25:11 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-16175</guid>
		<description>I think the problem with Complex conjugate-transpose is more subtle than a mere &quot;beginner&#039;s gotcha&quot;.  Specifically, the dot-operator notation in ALL other cases means &quot;like the operator, but applied element-by-element&quot;.  That is NOT what &quot;.&#039;&quot; means.  By analogy with the other dot-operators, it should mean &quot;conjugate of each element&quot;.

It is one thing to trip up beginners who have been &quot;damaged&quot; [Dijkstra&#039;s word] by other languages and therefore do not use the Matlab language appropriately.  It is quite another to introduce an INTERNAL inconsistency into that language.</description>
		<content:encoded><![CDATA[<p>I think the problem with Complex conjugate-transpose is more subtle than a mere &#8220;beginner&#8217;s gotcha&#8221;.  Specifically, the dot-operator notation in ALL other cases means &#8220;like the operator, but applied element-by-element&#8221;.  That is NOT what &#8220;.&#8217;&#8221; means.  By analogy with the other dot-operators, it should mean &#8220;conjugate of each element&#8221;.</p>
<p>It is one thing to trip up beginners who have been &#8220;damaged&#8221; [Dijkstra's word] by other languages and therefore do not use the Matlab language appropriately.  It is quite another to introduce an INTERNAL inconsistency into that language.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-16086</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Tue, 27 Feb 2007 13:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-16086</guid>
		<description>I agree with Arne that the i and j confusion can be a &quot;woe&quot;, but I would like to kindly disagree with his solution.  These variables are very commonly used as indices in algorithms.  The best solution to the &quot;beginner woe&quot; of redefining i and j is to not use i and j as complex units at all.  The constant &quot;1i&quot; should always be used instead.  A more common beginner woe is to abuse MATLAB&#039;s expressive power, when performance is an issue.  For example, allowing an array to grow arbitrarily, just by assigning a value to it, is very handy and sometimes a very useful solution to a problem.  It shouldn&#039;t be used if the array can be easily preallocated.  The same problem occurs when abusing sub-matrix assignment for sparse matrices (A(i,j)= ... when A is sparse).

Another problem I see is just the opposite ... when MATLAB&#039;s expressiveness is *not* used, resulting in ugly code.  Some beginners try to write MATLAB as if it&#039;s C/Fortran/Java.  They write ugly and lengthy loops when a simple, elegant, and easy-to-read one-line vector statement could be used instead.

My favorite abuse of MATLAB, however, is using x=inv(A)*b instead of x=A\b.  I would love it if MATLAB were to generate a warning message whenever it saw &quot;inv(A)*b&quot; ...</description>
		<content:encoded><![CDATA[<p>I agree with Arne that the i and j confusion can be a &#8220;woe&#8221;, but I would like to kindly disagree with his solution.  These variables are very commonly used as indices in algorithms.  The best solution to the &#8220;beginner woe&#8221; of redefining i and j is to not use i and j as complex units at all.  The constant &#8220;1i&#8221; should always be used instead.  A more common beginner woe is to abuse MATLAB&#8217;s expressive power, when performance is an issue.  For example, allowing an array to grow arbitrarily, just by assigning a value to it, is very handy and sometimes a very useful solution to a problem.  It shouldn&#8217;t be used if the array can be easily preallocated.  The same problem occurs when abusing sub-matrix assignment for sparse matrices (A(i,j)= &#8230; when A is sparse).</p>
<p>Another problem I see is just the opposite &#8230; when MATLAB&#8217;s expressiveness is *not* used, resulting in ugly code.  Some beginners try to write MATLAB as if it&#8217;s C/Fortran/Java.  They write ugly and lengthy loops when a simple, elegant, and easy-to-read one-line vector statement could be used instead.</p>
<p>My favorite abuse of MATLAB, however, is using x=inv(A)*b instead of x=A\b.  I would love it if MATLAB were to generate a warning message whenever it saw &#8220;inv(A)*b&#8221; &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arne Jenssen</title>
		<link>http://blogs.mathworks.com/loren/2007/02/21/beginner-woes/#comment-16081</link>
		<dc:creator>Arne Jenssen</dc:creator>
		<pubDate>Sat, 24 Feb 2007 20:43:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=78#comment-16081</guid>
		<description>I think that using i and j as a variable is a very bad habit commonly seen. This will make a mess when using complex values.</description>
		<content:encoded><![CDATA[<p>I think that using i and j as a variable is a very bad habit commonly seen. This will make a mess when using complex values.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

