<?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 video: Row and Column indexing</title>
	<atom:link href="http://blogs.mathworks.com/videos/2007/08/31/matlab-basics-video-row-and-column-indexing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/videos/2007/08/31/matlab-basics-video-row-and-column-indexing/</link>
	<description>Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.</description>
	<lastBuildDate>Fri, 10 Feb 2012 20:31:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2007/08/31/matlab-basics-video-row-and-column-indexing/#comment-521</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Fri, 14 Sep 2007 12:35:07 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2007/08/31/matlab-basics-video-row-and-column-indexing/#comment-521</guid>
		<description>That&#039;s right; I should have made that more clear.  If you&#039;re dealing with modest-sized problems, you won&#039;t see this effect.  The danger is when you want to scale up to solve large problems, and you wrongly conclude that MATLAB can&#039;t handle large problems.

A grad student at Stanford (Sep Kamvar) asked me why his pagerank-style computations in MATLAB were so exceedingly slow when dealing with a matrix of dimension about 680,000.  He showed me the code, and I saw x=A(i,:) in a loop.  Aha! ... and when it was fixed his run time was cut from maybe an hour to under a minute.  For his matrix, x=A(i,:) takes 0.16 seconds, but x=A(:,i) takes 0.0015 seconds.  If you&#039;re curious, you can try it with his matrix at http://www.cise.ufl.edu/research/sparse/matrices/Kamvar/ .

The profiler is a great tool for finding hot spots like this.  It won&#039;t help you to figure out why x=A(i,:) is slow and x=A(:,i) is 100&#039;s of times faster, though.  It may seem a little mysterious unless you look into how sparse matrices are stored in MATLAB.

Other &quot;gotcha&#039;s&quot; like this related to matrix indexing include, for full matrices and sparse alike:

x = [ ] ;
for i = 1:100000
   x (i) = i ;
end

for which mlint is a great tool for suggesting a much faster alternative.  The code above takes 50 seconds; using mlint&#039;s suggestion and changing the first line to x=zeros(1,100000); cuts the time to 0.12 seconds (yes, of course I&#039;m just doing x=1:100000; this is just an example).</description>
		<content:encoded><![CDATA[<p>That&#8217;s right; I should have made that more clear.  If you&#8217;re dealing with modest-sized problems, you won&#8217;t see this effect.  The danger is when you want to scale up to solve large problems, and you wrongly conclude that MATLAB can&#8217;t handle large problems.</p>
<p>A grad student at Stanford (Sep Kamvar) asked me why his pagerank-style computations in MATLAB were so exceedingly slow when dealing with a matrix of dimension about 680,000.  He showed me the code, and I saw x=A(i,:) in a loop.  Aha! &#8230; and when it was fixed his run time was cut from maybe an hour to under a minute.  For his matrix, x=A(i,:) takes 0.16 seconds, but x=A(:,i) takes 0.0015 seconds.  If you&#8217;re curious, you can try it with his matrix at <a href="http://www.cise.ufl.edu/research/sparse/matrices/Kamvar/" rel="nofollow">http://www.cise.ufl.edu/research/sparse/matrices/Kamvar/</a> .</p>
<p>The profiler is a great tool for finding hot spots like this.  It won&#8217;t help you to figure out why x=A(i,:) is slow and x=A(:,i) is 100&#8242;s of times faster, though.  It may seem a little mysterious unless you look into how sparse matrices are stored in MATLAB.</p>
<p>Other &#8220;gotcha&#8217;s&#8221; like this related to matrix indexing include, for full matrices and sparse alike:</p>
<p>x = [ ] ;<br />
for i = 1:100000<br />
   x (i) = i ;<br />
end</p>
<p>for which mlint is a great tool for suggesting a much faster alternative.  The code above takes 50 seconds; using mlint&#8217;s suggestion and changing the first line to x=zeros(1,100000); cuts the time to 0.12 seconds (yes, of course I&#8217;m just doing x=1:100000; this is just an example).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/videos/2007/08/31/matlab-basics-video-row-and-column-indexing/#comment-520</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 11 Sep 2007 20:33:24 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2007/08/31/matlab-basics-video-row-and-column-indexing/#comment-520</guid>
		<description>Tim gives good advice here.  It should be noted that the kinds of optimizations he is talking about shave small fractions of a second off of a single operation in typical situations.

These fractions add up though when you are in a loop that gets called many times.  The profiler is very good at helping to identify these places.  See my early videos for use of the profiler.

Doug</description>
		<content:encoded><![CDATA[<p>Tim gives good advice here.  It should be noted that the kinds of optimizations he is talking about shave small fractions of a second off of a single operation in typical situations.</p>
<p>These fractions add up though when you are in a loop that gets called many times.  The profiler is very good at helping to identify these places.  See my early videos for use of the profiler.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/videos/2007/08/31/matlab-basics-video-row-and-column-indexing/#comment-519</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Tue, 11 Sep 2007 20:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2007/08/31/matlab-basics-video-row-and-column-indexing/#comment-519</guid>
		<description>One mistake that both new and experienced MATLAB users make is to abuse A(i,j)=x and x=A(i,j) when A is a large sparse matrix.  Both work fine, but they can be very slow in some cases.  x=A(1,:) for example is much slower than x=A(:,1).  There are often better ways to write your code that avoids these slow cases.  For example, if you find yourself needing to do x=A(i,:) a lot, for a matrix A that doesn&#039;t change, then transpose A once and do x=A(:,i) instead (your code could be 100x faster as a result).  The sparse matrix data structure in MATLAB is best suited to whole-matrix operations, rather than row and column indexing.

None of this comment applies to full matrices, just sparse.  You don&#039;t get sparse matrices unless you ask for them, so if you&#039;re a MATLAB newcomer who also has no need for sparse matrices, then please ignore my comment.</description>
		<content:encoded><![CDATA[<p>One mistake that both new and experienced MATLAB users make is to abuse A(i,j)=x and x=A(i,j) when A is a large sparse matrix.  Both work fine, but they can be very slow in some cases.  x=A(1,:) for example is much slower than x=A(:,1).  There are often better ways to write your code that avoids these slow cases.  For example, if you find yourself needing to do x=A(i,:) a lot, for a matrix A that doesn&#8217;t change, then transpose A once and do x=A(:,i) instead (your code could be 100x faster as a result).  The sparse matrix data structure in MATLAB is best suited to whole-matrix operations, rather than row and column indexing.</p>
<p>None of this comment applies to full matrices, just sparse.  You don&#8217;t get sparse matrices unless you ask for them, so if you&#8217;re a MATLAB newcomer who also has no need for sparse matrices, then please ignore my comment.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

