Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Avoiding loops in a symmetric matrix.
Date: Fri, 5 Dec 2008 16:36:01 +0000 (UTC)
Organization: Xoran Technologies
Lines: 22
Message-ID: <ghbl9h$9qi$1@fred.mathworks.com>
References: <ghbdre$ahh$1@fred.mathworks.com> <ghbgle$s08$1@fred.mathworks.com> <ghbhje$e2j$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228494961 10066 172.30.248.35 (5 Dec 2008 16:36:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 5 Dec 2008 16:36:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:505219


"Jose " <jose.l.vega@gmail.com> wrote in message <ghbhje$e2j$1@fred.mathworks.com>...
> Hi Matt, could you explain me how i can do it with circshift?
> I need to make the differences of 200 vectors and 100 components,
> it take 5 minutes, and -i have to get it in secs, :)
> I wrote a short example, to explain my problem.
> Cheers,
> Jose.

Well, for example, if your original matrix is u and you want to subtract each column of u from its neighbour to the right, you do the following

delta1=u-circshift(u,[0,-1]);

From there, I think it's obvious how you do the remaining delta's.

A few more tips

1. Pre-allocate your delta array rather than letting it grow by concatentation.

2. It's faster to loop over matrix columns than rows. So, pre-tranpose your matrix to facilitate this.