Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!g1g2000yqh.googlegroups.com!not-for-mail
From: arun <aragorn168b@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Efficient computation: differences of column vectors of matrix
Date: Wed, 1 Jul 2009 03:07:08 -0700 (PDT)
Organization: http://groups.google.com
Lines: 41
Message-ID: <031bd8b8-27c1-4e73-93d2-fe2b9d06069c@g1g2000yqh.googlegroups.com>
References: <cd6f7a80-0651-417d-ac72-88d6b326e1fe@b14g2000yqd.googlegroups.com> 
	<h2evr5$faj$1@fred.mathworks.com>
NNTP-Posting-Host: 192.124.26.250
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1246442828 1297 127.0.0.1 (1 Jul 2009 10:07:08 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 1 Jul 2009 10:07:08 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: g1g2000yqh.googlegroups.com; posting-host=192.124.26.250; 
	posting-account=fyqXpgoAAABqt-0BifyaNxmZhzggFACu
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) 
	Gecko/20090624 Firefox/3.5,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:551935


On Jul 1, 8:31 am, "Bruno Luong" <b.lu...@fogale.findmycountry> wrote:
> arun <aragorn168b@gm%ail.com> wrote in message <cd6f7a80-0651-417d-ac72-88d6b326e...@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

Hi Bruno,
thank you for your help. But there seems to be a problem.

The J2 matrix seems to generate the indices properly. But, suppose J2
= [1,1,1,2,2,3; 2,3,4,3,4,4] then, A(:,J2(:,1)) will simply choose a
matrix which has the first column repeated three times and 2nd column
repeated 2 times and third column repeated 1 time... I hope I
explained clear enough to understand what hte problem is...
However, thank you.  I will also try to work on it.

regards,
arun.