<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043</link>
    <title>MATLAB Central Newsreader - Efficient computation: differences of column vectors of matrix</title>
    <description>Feed for thread: Efficient computation: differences of column vectors of 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>Wed, 01 Jul 2009 00:17:35 -0400</pubDate>
      <title>Efficient computation: differences of column vectors of matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043#661698</link>
      <author>arun</author>
      <description>Hi and thanks for the help,&lt;br&gt;
&lt;br&gt;
I have a matrix say&lt;br&gt;
&lt;br&gt;
A = [a1,b1,c1,d1; a2,b2,c2,d2; a3,b3,c3,d3; a4,b4,c4,d4]&lt;br&gt;
&lt;br&gt;
now, I want the differences across the columns as,&lt;br&gt;
&lt;br&gt;
B = [(a1-a2),(a1-a3),(a1-a4),(a2-a3),(a2-a4),(a3-a4);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(b1-b2),(b1-b3),(b1-b4),(b2-b3),(b2-b4),(b3-b4);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(c1-c2),(c1-c3),(c1-c4),(c2-c3),(c2-c4),(c3-c4);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(d1-d2),(d1-d3),(d1-d4),(d2-d3),(d2-d4),(d3-d4)]&lt;br&gt;
&lt;br&gt;
i would like to do this efficiently in Matlab because, my A =&lt;br&gt;
200*250000 and so, after doing for each of the 200 columns... B matrix&lt;br&gt;
would be 200*199/2= 19,900 * 250000. I would like to know if it could&lt;br&gt;
be done efficiently (since its across columns). if space is a problem,&lt;br&gt;
i can subdivide the matrix, it shouldn't be an issue.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
thanks again,&lt;br&gt;
regards,&lt;br&gt;
arun.</description>
    </item>
    <item>
      <pubDate>Wed, 01 Jul 2009 06:31:01 -0400</pubDate>
      <title>Re: Efficient computation: differences of column vectors of matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043#661717</link>
      <author>Bruno Luong</author>
      <description>arun &amp;lt;aragorn168b@gm%ail.com&amp;gt; wrote in message &amp;lt;cd6f7a80-0651-417d-ac72-88d6b326e1fe@b14g2000yqd.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi and thanks for the help,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have a matrix say&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; A = [a1,b1,c1,d1; a2,b2,c2,d2; a3,b3,c3,d3; a4,b4,c4,d4]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; now, I want the differences across the columns as,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; B = [(a1-a2),(a1-a3),(a1-a4),(a2-a3),(a2-a4),(a3-a4);&lt;br&gt;
&amp;gt;        (b1-b2),(b1-b3),(b1-b4),(b2-b3),(b2-b4),(b3-b4);&lt;br&gt;
&amp;gt;        (c1-c2),(c1-c3),(c1-c4),(c2-c3),(c2-c4),(c3-c4);&lt;br&gt;
&amp;gt;        (d1-d2),(d1-d3),(d1-d4),(d2-d3),(d2-d4),(d3-d4)]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; i would like to do this efficiently in Matlab because, my A =&lt;br&gt;
&amp;gt; 200*250000 and so, after doing for each of the 200 columns... B matrix&lt;br&gt;
&amp;gt; would be 200*199/2= 19,900 * 250000. I would like to know if it could&lt;br&gt;
&amp;gt; be done efficiently (since its across columns). if space is a problem,&lt;br&gt;
&amp;gt; i can subdivide the matrix, it shouldn't be an issue.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
A=ceil(10*rand(10,4));&lt;br&gt;
&lt;br&gt;
J2=nchoosek(1:size(A,2),2);&lt;br&gt;
A(:,J2(:,1))-A(:,J2(:,2))&lt;br&gt;
&lt;br&gt;
% Bruno</description>
    </item>
    <item>
      <pubDate>Wed, 01 Jul 2009 10:07:08 -0400</pubDate>
      <title>Re: Efficient computation: differences of column vectors of matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043#661760</link>
      <author>arun</author>
      <description>On Jul 1, 8:31&#160;am, &quot;Bruno Luong&quot; &amp;lt;b.lu...@fogale.findmycountry&amp;gt; wrote:&lt;br&gt;
&amp;gt; arun &amp;lt;aragorn168b@gm%ail.com&amp;gt; wrote in message &amp;lt;cd6f7a80-0651-417d-ac72-88d6b326e...@b14g2000yqd.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi and thanks for the help,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I have a matrix say&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; A = [a1,b1,c1,d1; a2,b2,c2,d2; a3,b3,c3,d3; a4,b4,c4,d4]&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; now, I want the differences across the columns as,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; B = [(a1-a2),(a1-a3),(a1-a4),(a2-a3),(a2-a4),(a3-a4);&lt;br&gt;
&amp;gt; &amp;gt; &#160; &#160; &#160; &#160;(b1-b2),(b1-b3),(b1-b4),(b2-b3),(b2-b4),(b3-b4);&lt;br&gt;
&amp;gt; &amp;gt; &#160; &#160; &#160; &#160;(c1-c2),(c1-c3),(c1-c4),(c2-c3),(c2-c4),(c3-c4);&lt;br&gt;
&amp;gt; &amp;gt; &#160; &#160; &#160; &#160;(d1-d2),(d1-d3),(d1-d4),(d2-d3),(d2-d4),(d3-d4)]&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; i would like to do this efficiently in Matlab because, my A =&lt;br&gt;
&amp;gt; &amp;gt; 200*250000 and so, after doing for each of the 200 columns... B matrix&lt;br&gt;
&amp;gt; &amp;gt; would be 200*199/2= 19,900 * 250000. I would like to know if it could&lt;br&gt;
&amp;gt; &amp;gt; be done efficiently (since its across columns). if space is a problem,&lt;br&gt;
&amp;gt; &amp;gt; i can subdivide the matrix, it shouldn't be an issue.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; A=ceil(10*rand(10,4));&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; J2=nchoosek(1:size(A,2),2);&lt;br&gt;
&amp;gt; A(:,J2(:,1))-A(:,J2(:,2))&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % Bruno&lt;br&gt;
&lt;br&gt;
Hi Bruno,&lt;br&gt;
thank you for your help. But there seems to be a problem.&lt;br&gt;
&lt;br&gt;
The J2 matrix seems to generate the indices properly. But, suppose J2&lt;br&gt;
= [1,1,1,2,2,3; 2,3,4,3,4,4] then, A(:,J2(:,1)) will simply choose a&lt;br&gt;
matrix which has the first column repeated three times and 2nd column&lt;br&gt;
repeated 2 times and third column repeated 1 time... I hope I&lt;br&gt;
explained clear enough to understand what hte problem is...&lt;br&gt;
However, thank you.  I will also try to work on it.&lt;br&gt;
&lt;br&gt;
regards,&lt;br&gt;
arun.</description>
    </item>
    <item>
      <pubDate>Wed, 01 Jul 2009 10:15:06 -0400</pubDate>
      <title>Re: Efficient computation: differences of column vectors of matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043#661762</link>
      <author>arun</author>
      <description>On Jul 1, 8:31&#160;am, &quot;Bruno Luong&quot; &amp;lt;b.lu...@fogale.findmycountry&amp;gt; wrote:&lt;br&gt;
&amp;gt; arun &amp;lt;aragorn168b@gm%ail.com&amp;gt; wrote in message &amp;lt;cd6f7a80-0651-417d-ac72-88d6b326e...@b14g2000yqd.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi and thanks for the help,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I have a matrix say&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; A = [a1,b1,c1,d1; a2,b2,c2,d2; a3,b3,c3,d3; a4,b4,c4,d4]&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; now, I want the differences across the columns as,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; B = [(a1-a2),(a1-a3),(a1-a4),(a2-a3),(a2-a4),(a3-a4);&lt;br&gt;
&amp;gt; &amp;gt; &#160; &#160; &#160; &#160;(b1-b2),(b1-b3),(b1-b4),(b2-b3),(b2-b4),(b3-b4);&lt;br&gt;
&amp;gt; &amp;gt; &#160; &#160; &#160; &#160;(c1-c2),(c1-c3),(c1-c4),(c2-c3),(c2-c4),(c3-c4);&lt;br&gt;
&amp;gt; &amp;gt; &#160; &#160; &#160; &#160;(d1-d2),(d1-d3),(d1-d4),(d2-d3),(d2-d4),(d3-d4)]&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; i would like to do this efficiently in Matlab because, my A =&lt;br&gt;
&amp;gt; &amp;gt; 200*250000 and so, after doing for each of the 200 columns... B matrix&lt;br&gt;
&amp;gt; &amp;gt; would be 200*199/2= 19,900 * 250000. I would like to know if it could&lt;br&gt;
&amp;gt; &amp;gt; be done efficiently (since its across columns). if space is a problem,&lt;br&gt;
&amp;gt; &amp;gt; i can subdivide the matrix, it shouldn't be an issue.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; A=ceil(10*rand(10,4));&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; J2=nchoosek(1:size(A,2),2);&lt;br&gt;
&amp;gt; A(:,J2(:,1))-A(:,J2(:,2))&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % Bruno&lt;br&gt;
&lt;br&gt;
Hi I just found the modification which works. I just have to check if&lt;br&gt;
it works faster for bigger matrices.&lt;br&gt;
thank you.&lt;br&gt;
&lt;br&gt;
its just,&lt;br&gt;
A(J2(:,1),:) - A(J2(:,2),:)&lt;br&gt;
&lt;br&gt;
best,&lt;br&gt;
arun.</description>
    </item>
    <item>
      <pubDate>Wed, 01 Jul 2009 11:48:01 -0400</pubDate>
      <title>Re: Efficient computation: differences of column vectors of matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043#661780</link>
      <author>Bruno Luong</author>
      <description>arun &amp;lt;aragorn168b@gmail.com&amp;gt; wrote in message &amp;lt;63985d2a-adf8-47c9-aaa3-52e0a1cb9ede@37g2000yqp.googlegroups.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; its just,&lt;br&gt;
&amp;gt; A(J2(:,1),:) - A(J2(:,2),:)&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Unless I'm mistaking, this is NOT what you have described in the example in the post #1. But anyway you seem to know what you want.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Wed, 01 Jul 2009 12:10:03 -0400</pubDate>
      <title>Re: Efficient computation: differences of column vectors of matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043#661783</link>
      <author>oruganti murthy</author>
      <description>Hi&lt;br&gt;
I'm also having a similar problem. &lt;br&gt;
I am having two matrices containing 150 size vectors. say A is 5000x150 aand B is 1500x150. I want to find pairwise euclidean distance between vectors of A and B. i.e. I want 5000x1500 matrix. &lt;br&gt;
Is there any efficient way to do it. &lt;br&gt;
If not distance, even absolute difference is fine. &lt;br&gt;
Because at next level these numbers (5000 changes to 25000)also increase and I am encountering OUT of MEMORY or very time consuming problems.&lt;br&gt;
Thanking you very much,&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
regards,&lt;br&gt;
ramana&lt;br&gt;
&lt;br&gt;
&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;h2fidh$mpl$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; arun &amp;lt;aragorn168b@gmail.com&amp;gt; wrote in message &amp;lt;63985d2a-adf8-47c9-aaa3-52e0a1cb9ede@37g2000yqp.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; its just,&lt;br&gt;
&amp;gt; &amp;gt; A(J2(:,1),:) - A(J2(:,2),:)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Unless I'm mistaking, this is NOT what you have described in the example in the post #1. But anyway you seem to know what you want.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno</description>
    </item>
    <item>
      <pubDate>Wed, 01 Jul 2009 12:36:01 -0400</pubDate>
      <title>Re: Efficient computation: differences of column vectors of matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043#661796</link>
      <author>Bruno Luong</author>
      <description>&quot;oruganti murthy&quot; &amp;lt;omurthy@yahoo.com&amp;gt; wrote in message &amp;lt;h2fjmr$gdn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi&lt;br&gt;
&amp;gt; I'm also having a similar problem. &lt;br&gt;
&amp;gt; I am having two matrices containing 150 size vectors. say A is 5000x150 aand B is 1500x150. I want to find pairwise euclidean distance between vectors of A and B. i.e. I want 5000x1500 matrix. &lt;br&gt;
&amp;gt; Is there any efficient way to do it. &lt;br&gt;
&amp;gt; If not distance, even absolute difference is fine. &lt;br&gt;
&amp;gt; Because at next level these numbers (5000 changes to 25000)also increase and I am encountering OUT of MEMORY or very time consuming problems.&lt;br&gt;
&amp;gt; Thanking you very much,&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Take a look at function BSXFUN&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Thu, 02 Jul 2009 11:33:47 -0400</pubDate>
      <title>Re: Efficient computation: differences of column vectors of matrix</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255043#662159</link>
      <author>arun</author>
      <description>On Jul 1, 2:36&#160;pm, &quot;Bruno Luong&quot; &amp;lt;b.lu...@fogale.findmycountry&amp;gt; wrote:&lt;br&gt;
&amp;gt; &quot;oruganti murthy&quot; &amp;lt;omur...@yahoo.com&amp;gt; wrote in message &amp;lt;h2fjmr$gd...@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi&lt;br&gt;
&amp;gt; &amp;gt; I'm also having a similar problem.&lt;br&gt;
&amp;gt; &amp;gt; I am having two matrices containing 150 size vectors. say A is 5000x150 aand B is 1500x150. I want to find pairwise euclidean distance between vectors of A and B. i.e. I want 5000x1500 matrix.&lt;br&gt;
&amp;gt; &amp;gt; Is there any efficient way to do it.&lt;br&gt;
&amp;gt; &amp;gt; If not distance, even absolutedifferenceis fine.&lt;br&gt;
&amp;gt; &amp;gt; Because at next level these numbers (5000 changes to 25000)also increase and I am encountering OUT of MEMORY or very time consuming problems.&lt;br&gt;
&amp;gt; &amp;gt; Thanking you very much,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Take a look at function BSXFUN&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
Hi Bruno,&lt;br&gt;
yes, my representation of the final matrix was incorrect. thank you,&lt;br&gt;
arun.</description>
    </item>
  </channel>
</rss>

