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 19:07:01 +0000 (UTC)
Organization: Univ of Newcastle upon Tyne
Lines: 58
Message-ID: <ghbu4l$q18$1@fred.mathworks.com>
References: <ghbdre$ahh$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 1228504021 26664 172.30.248.35 (5 Dec 2008 19:07:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 5 Dec 2008 19:07:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1511480
Xref: news.mathworks.com comp.soft-sys.matlab:505264


clc;
clear all;
u=[1 2 3; 3 4 6;5 6 7 ]
delta1=u-circshift(u,[0,-1])

u =

     1     2     3
     3     4     6
     5     6     7


delta1 =

    -1    -1     2 ...first colum: u(:,1)-u(:,2)
    -1    -2     3....second column: u(:,2)-u(:,3)
    -1    -1     2....third column: (:,3)-u(:,1)

But...i am more interested in the sequence:
u(:,1)-u(:,2),u(:,1)-u(:,3)
And i do not know how you can arrange from your idea at my final matrix.
ome idea?
Cheers,
Jose.

Thanks for the tips.

Ok, you are right...but to me is not obvious :)...how I can generate the
remaind deltas.



"Jose " <jose.l.vega@gmail.com> wrote in message <ghbdre$ahh$1@fred.mathworks.com>...
> Hi,
> I have 10 vectors with 10 components, u(1:10,1:10).
> 
> And I am interested to calculated the differences between vectors  avoiding the diagonal components, because I am not interested in a high correlation between components.
> 
> This is my code, it works, but is not efficient, I would like to avoid the loops, but
> I do not know how I can do it:
> 
> for i=1:10
>    
>     for j=1:10
>         if j~=i 
>         dx=u(i,:)-u(j,:);
>         
>    if i==1 & j==2
>    delta=dx;
>    else 
>        delta=[delta;dx];
>    end
>         end
>         end
> 
> Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.
> Thanks in advance,
> Jose.