Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Efficient computation: differences of column vectors of matrix
Date: Wed, 1 Jul 2009 06:31:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 27
Message-ID: <h2evr5$faj$1@fred.mathworks.com>
References: <cd6f7a80-0651-417d-ac72-88d6b326e1fe@b14g2000yqd.googlegroups.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
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 1246429861 15699 172.30.248.37 (1 Jul 2009 06:31:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 1 Jul 2009 06:31:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:551892


arun <aragorn168b@gm%ail.com> wrote in message <cd6f7a80-0651-417d-ac72-88d6b326e1fe@b14g2000yqd.googlegroups.com>...
> Hi and thanks for the help,
> 
> I have a matrix say
> 
> A = [a1,b1,c1,d1; a2,b2,c2,d2; a3,b3,c3,d3; a4,b4,c4,d4]
> 
> now, I want the differences across the columns as,
> 
> B = [(a1-a2),(a1-a3),(a1-a4),(a2-a3),(a2-a4),(a3-a4);
>        (b1-b2),(b1-b3),(b1-b4),(b2-b3),(b2-b4),(b3-b4);
>        (c1-c2),(c1-c3),(c1-c4),(c2-c3),(c2-c4),(c3-c4);
>        (d1-d2),(d1-d3),(d1-d4),(d2-d3),(d2-d4),(d3-d4)]
> 
> i would like to do this efficiently in Matlab because, my A =
> 200*250000 and so, after doing for each of the 200 columns... B matrix
> would be 200*199/2= 19,900 * 250000. I would like to know if it could
> be done efficiently (since its across columns). if space is a problem,
> i can subdivide the matrix, it shouldn't be an issue.
> 

A=ceil(10*rand(10,4));

J2=nchoosek(1:size(A,2),2);
A(:,J2(:,1))-A(:,J2(:,2))

% Bruno