<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505</link>
    <title>MATLAB Central Newsreader - Avoiding loops in a symmetric matrix.</title>
    <description>Feed for thread: Avoiding loops in a symmetric matrix.</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 05 Dec 2008 14:29:02 -0500</pubDate>
      <title>Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615247</link>
      <author>Jose </author>
      <description>Hi,&lt;br&gt;
I have 10 vectors with 10 components, u(1:10,1:10).&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
This is my code, it works, but is not efficient, I would like to avoid the loops, but&lt;br&gt;
I do not know how I can do it:&lt;br&gt;
&lt;br&gt;
for i=1:10&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for j=1:10&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if j~=i &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;if i==1 &amp; j==2&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;delta=dx;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;else &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delta=[delta;dx];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&lt;br&gt;
Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.&lt;br&gt;
Thanks in advance,&lt;br&gt;
Jose.</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 15:17:02 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615266</link>
      <author>Matt </author>
      <description>&quot;Jose &quot; &amp;lt;jose.l.vega@gmail.com&amp;gt; wrote in message &amp;lt;ghbdre$ahh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I have 10 vectors with 10 components, u(1:10,1:10).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is my code, it works, but is not efficient, I would like to avoid the loops, but&lt;br&gt;
&amp;gt; I do not know how I can do it:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:10&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;     for j=1:10&lt;br&gt;
&amp;gt;         if j~=i &lt;br&gt;
&amp;gt;         dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;gt;         &lt;br&gt;
&amp;gt;    if i==1 &amp; j==2&lt;br&gt;
&amp;gt;    delta=dx;&lt;br&gt;
&amp;gt;    else &lt;br&gt;
&amp;gt;        delta=[delta;dx];&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.&lt;br&gt;
&amp;gt; Thanks in advance,&lt;br&gt;
&amp;gt; Jose.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
You can eliminate one loop using circshift(). I don't see a way you can avoid both.&lt;br&gt;
&lt;br&gt;
But why do you care? It's such a small amount of data.</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 15:33:02 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615269</link>
      <author>Jose </author>
      <description>Hi Matt, could you explain me how i can do it with circshift?&lt;br&gt;
I need to make the differences of 200 vectors and 100 components,&lt;br&gt;
it take 5 minutes, and -i have to get it in secs, :)&lt;br&gt;
I wrote a short example, to explain my problem.&lt;br&gt;
Cheers,&lt;br&gt;
Jose.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Matt&quot; &amp;lt;mjacobson.removethis@xorantech.com&amp;gt; wrote in message &amp;lt;ghbgle$s08$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Jose &quot; &amp;lt;jose.l.vega@gmail.com&amp;gt; wrote in message &amp;lt;ghbdre$ahh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; I have 10 vectors with 10 components, u(1:10,1:10).&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; This is my code, it works, but is not efficient, I would like to avoid the loops, but&lt;br&gt;
&amp;gt; &amp;gt; I do not know how I can do it:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for i=1:10&lt;br&gt;
&amp;gt; &amp;gt;    &lt;br&gt;
&amp;gt; &amp;gt;     for j=1:10&lt;br&gt;
&amp;gt; &amp;gt;         if j~=i &lt;br&gt;
&amp;gt; &amp;gt;         dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;gt; &amp;gt;         &lt;br&gt;
&amp;gt; &amp;gt;    if i==1 &amp; j==2&lt;br&gt;
&amp;gt; &amp;gt;    delta=dx;&lt;br&gt;
&amp;gt; &amp;gt;    else &lt;br&gt;
&amp;gt; &amp;gt;        delta=[delta;dx];&lt;br&gt;
&amp;gt; &amp;gt;    end&lt;br&gt;
&amp;gt; &amp;gt;         end&lt;br&gt;
&amp;gt; &amp;gt;         end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.&lt;br&gt;
&amp;gt; &amp;gt; Thanks in advance,&lt;br&gt;
&amp;gt; &amp;gt; Jose.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You can eliminate one loop using circshift(). I don't see a way you can avoid both.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; But why do you care? It's such a small amount of data.&lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 16:36:01 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615289</link>
      <author>Matt </author>
      <description>&quot;Jose &quot; &amp;lt;jose.l.vega@gmail.com&amp;gt; wrote in message &amp;lt;ghbhje$e2j$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi Matt, could you explain me how i can do it with circshift?&lt;br&gt;
&amp;gt; I need to make the differences of 200 vectors and 100 components,&lt;br&gt;
&amp;gt; it take 5 minutes, and -i have to get it in secs, :)&lt;br&gt;
&amp;gt; I wrote a short example, to explain my problem.&lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; Jose.&lt;br&gt;
&lt;br&gt;
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&lt;br&gt;
&lt;br&gt;
delta1=u-circshift(u,[0,-1]);&lt;br&gt;
&lt;br&gt;
From there, I think it's obvious how you do the remaining delta's.&lt;br&gt;
&lt;br&gt;
A few more tips&lt;br&gt;
&lt;br&gt;
1. Pre-allocate your delta array rather than letting it grow by concatentation.&lt;br&gt;
&lt;br&gt;
2. It's faster to loop over matrix columns than rows. So, pre-tranpose your matrix to facilitate this.</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 19:07:01 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615334</link>
      <author>Jose </author>
      <description>clc;&lt;br&gt;
clear all;&lt;br&gt;
u=[1 2 3; 3 4 6;5 6 7 ]&lt;br&gt;
delta1=u-circshift(u,[0,-1])&lt;br&gt;
&lt;br&gt;
u =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1     2     3&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3     4     6&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5     6     7&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
delta1 =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-1    -1     2 ...first colum: u(:,1)-u(:,2)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-1    -2     3....second column: u(:,2)-u(:,3)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-1    -1     2....third column: (:,3)-u(:,1)&lt;br&gt;
&lt;br&gt;
But...i am more interested in the sequence:&lt;br&gt;
u(:,1)-u(:,2),u(:,1)-u(:,3)&lt;br&gt;
And i do not know how you can arrange from your idea at my final matrix.&lt;br&gt;
ome idea?&lt;br&gt;
Cheers,&lt;br&gt;
Jose.&lt;br&gt;
&lt;br&gt;
Thanks for the tips.&lt;br&gt;
&lt;br&gt;
Ok, you are right...but to me is not obvious :)...how I can generate the&lt;br&gt;
remaind deltas.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Jose &quot; &amp;lt;jose.l.vega@gmail.com&amp;gt; wrote in message &amp;lt;ghbdre$ahh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I have 10 vectors with 10 components, u(1:10,1:10).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is my code, it works, but is not efficient, I would like to avoid the loops, but&lt;br&gt;
&amp;gt; I do not know how I can do it:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:10&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;     for j=1:10&lt;br&gt;
&amp;gt;         if j~=i &lt;br&gt;
&amp;gt;         dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;gt;         &lt;br&gt;
&amp;gt;    if i==1 &amp; j==2&lt;br&gt;
&amp;gt;    delta=dx;&lt;br&gt;
&amp;gt;    else &lt;br&gt;
&amp;gt;        delta=[delta;dx];&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.&lt;br&gt;
&amp;gt; Thanks in advance,&lt;br&gt;
&amp;gt; Jose.</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 19:20:18 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615336</link>
      <author>Matt </author>
      <description>&amp;gt; Ok, you are right...but to me is not obvious :)...how I can generate the&lt;br&gt;
&amp;gt; remaind deltas.&lt;br&gt;
&lt;br&gt;
If it's not obvious, I'm pretty sure you haven't bothered to do &quot;help circshift&quot;&lt;br&gt;
:)</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 19:51:02 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615344</link>
      <author>Jose </author>
      <description>Please, Matt, can yu written down the code complete for the matrix u?&lt;br&gt;
I spent all the day try to vectorizing the matrix  avoiding loops.&lt;br&gt;
Here you are.&lt;br&gt;
u=[1 2 3; 4 5 6; 6 7 8]&lt;br&gt;
&lt;br&gt;
clear all;&lt;br&gt;
clc;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
u=[1 2 3; 4 5 6; 6 7 8]&lt;br&gt;
&lt;br&gt;
tic&lt;br&gt;
nc=size(u,2);&lt;br&gt;
&lt;br&gt;
delta=zeros(0,nc); %pre-llocated delta&lt;br&gt;
&lt;br&gt;
nt=length(u(:,1))&lt;br&gt;
for i=1:nt&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for j=1:nt&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delta=[delta;dx];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
delta&lt;br&gt;
toc&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0     0     0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-3    -3    -3&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-5    -5    -5&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3     3     3&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0     0     0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-2    -2    -2&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5     5     5&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2     2     2&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0     0     0&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
You can send me your code, where you avoid the j-loop?&lt;br&gt;
&lt;br&gt;
I do not need the diagonal.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thanks in advance,&lt;br&gt;
Jose.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Jose &quot; &amp;lt;jose.l.vega@gmail.com&amp;gt; wrote in message &amp;lt;ghbdre$ahh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I have 10 vectors with 10 components, u(1:10,1:10).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is my code, it works, but is not efficient, I would like to avoid the loops, but&lt;br&gt;
&amp;gt; I do not know how I can do it:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:10&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;     for j=1:10&lt;br&gt;
&amp;gt;         if j~=i &lt;br&gt;
&amp;gt;         dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;gt;         &lt;br&gt;
&amp;gt;    if i==1 &amp; j==2&lt;br&gt;
&amp;gt;    delta=dx;&lt;br&gt;
&amp;gt;    else &lt;br&gt;
&amp;gt;        delta=[delta;dx];&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.&lt;br&gt;
&amp;gt; Thanks in advance,&lt;br&gt;
&amp;gt; Jose.</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 20:28:03 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615349</link>
      <author>Matt </author>
      <description>&amp;gt; You can send me your code, where you avoid the j-loop?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I do not need the diagonal.&lt;br&gt;
&lt;br&gt;
OK. Here's what I have. However, it produces an array DeltaUnsorted whose columns may not be in the order you want. That part, I leave to you...&lt;br&gt;
&lt;br&gt;
u=rand(100,200); &lt;br&gt;
nn=size(u,2); &lt;br&gt;
Z=cell(1,nn-1);&lt;br&gt;
&lt;br&gt;
tic; &lt;br&gt;
&amp;nbsp;for ii=1:nn-1, &lt;br&gt;
&amp;nbsp;&amp;nbsp;Z{ii}=u-circshift(u,[0,-ii]);&lt;br&gt;
&amp;nbsp;end, &lt;br&gt;
DeltaUnsorted=[Z{:}]; &lt;br&gt;
toc&lt;br&gt;
&lt;br&gt;
Elapsed time is 0.165232 seconds.</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 21:00:21 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615360</link>
      <author>Jose </author>
      <description>Thaks, thank you very much.&lt;br&gt;
It is like i need, because i am not interested in the order, only in the differences.&lt;br&gt;
Well done Matt,&lt;br&gt;
Cheers,&lt;br&gt;
Jose.&lt;br&gt;
&lt;br&gt;
&quot;Jose &quot; &amp;lt;jose.l.vega@gmail.com&amp;gt; wrote in message &amp;lt;ghbdre$ahh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I have 10 vectors with 10 components, u(1:10,1:10).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is my code, it works, but is not efficient, I would like to avoid the loops, but&lt;br&gt;
&amp;gt; I do not know how I can do it:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:10&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;     for j=1:10&lt;br&gt;
&amp;gt;         if j~=i &lt;br&gt;
&amp;gt;         dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;gt;         &lt;br&gt;
&amp;gt;    if i==1 &amp; j==2&lt;br&gt;
&amp;gt;    delta=dx;&lt;br&gt;
&amp;gt;    else &lt;br&gt;
&amp;gt;        delta=[delta;dx];&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.&lt;br&gt;
&amp;gt; Thanks in advance,&lt;br&gt;
&amp;gt; Jose.</description>
    </item>
    <item>
      <pubDate>Fri, 05 Dec 2008 21:46:01 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615366</link>
      <author>Roger Stafford</author>
      <description>&quot;Jose &quot; &amp;lt;jose.l.vega@gmail.com&amp;gt; wrote in message &amp;lt;ghbdre$ahh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I have 10 vectors with 10 components, u(1:10,1:10).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is my code, it works, but is not efficient, I would like to avoid the loops, but&lt;br&gt;
&amp;gt; I do not know how I can do it:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:10&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;     for j=1:10&lt;br&gt;
&amp;gt;         if j~=i &lt;br&gt;
&amp;gt;         dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;gt;         &lt;br&gt;
&amp;gt;    if i==1 &amp; j==2&lt;br&gt;
&amp;gt;    delta=dx;&lt;br&gt;
&amp;gt;    else &lt;br&gt;
&amp;gt;        delta=[delta;dx];&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.&lt;br&gt;
&amp;gt; Thanks in advance,&lt;br&gt;
&amp;gt; Jose.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;You can also do it this way:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;n = size(u,1);&lt;br&gt;
&amp;nbsp;[I,J] = meshgrid(1:n,1:n);&lt;br&gt;
&amp;nbsp;p = 1+(n+1)*(0:n-1);&lt;br&gt;
&amp;nbsp;I(p) = []; J(p) = [];&lt;br&gt;
&amp;nbsp;delta2 = u(I,:)-u(J,:);&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Mon, 08 Dec 2008 16:28:02 -0500</pubDate>
      <title>Re: Avoiding loops in a symmetric matrix.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240505#615705</link>
      <author>Jose </author>
      <description>Thanks Roger.&lt;br&gt;
Jose.&lt;br&gt;
&lt;br&gt;
&quot;Jose &quot; &amp;lt;jose.l.vega@gmail.com&amp;gt; wrote in message &amp;lt;ghbdre$ahh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I have 10 vectors with 10 components, u(1:10,1:10).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is my code, it works, but is not efficient, I would like to avoid the loops, but&lt;br&gt;
&amp;gt; I do not know how I can do it:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:10&lt;br&gt;
&amp;gt;    &lt;br&gt;
&amp;gt;     for j=1:10&lt;br&gt;
&amp;gt;         if j~=i &lt;br&gt;
&amp;gt;         dx=u(i,:)-u(j,:);&lt;br&gt;
&amp;gt;         &lt;br&gt;
&amp;gt;    if i==1 &amp; j==2&lt;br&gt;
&amp;gt;    delta=dx;&lt;br&gt;
&amp;gt;    else &lt;br&gt;
&amp;gt;        delta=[delta;dx];&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Please, anyone can help me to try to built the delta correlation matrix of another form more efficient.&lt;br&gt;
&amp;gt; Thanks in advance,&lt;br&gt;
&amp;gt; Jose.</description>
    </item>
  </channel>
</rss>

