Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorize silly matrix
Date: Mon, 20 Apr 2009 02:54:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <gsgo49$ejh$1@fred.mathworks.com>
References: <2b9d378f-1af9-40c1-81dc-1ad16f709c85@c12g2000yqc.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1240196041 14961 172.30.248.37 (20 Apr 2009 02:54:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 20 Apr 2009 02:54:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:533958

yoshis88@gmail.com wrote in message <2b9d378f-1af9-40c1-81dc-1ad16f709c85@c12g2000yqc.googlegroups.com>...
> Dear comp.soft-sys.matlab,
> 
> First post here!
> 
> Anyway, I have a chunk of code that has been bothering me.  I'm
> somewhat of a veteran MATLAB/Octave user, and anytime I see a for
> loop, the coder in me wants to vectorize it.  So, here's something
> which I have been picking on for quite a while.
> 
> function A = createSillyMatrix(r,c)
> for k = 1:r
>     for m = 1:c
>         A(k,m) = k+m-1
>     end
> end
> 
> Any thoughts?

 A = hankel(1:r,r:r+c-1);

Roger Stafford