Path: news.mathworks.com!not-for-mail From: "Skirt Zhang" <silence_qunzi@hotmail.com> Newsgroups: comp.soft-sys.matlab Subject: Re: How to reduce the combinations' dimension--speed up my cross product Date: Tue, 12 Jul 2011 07:07:08 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 36 Message-ID: <ivgrqs$6om$1@newscl01ah.mathworks.com> References: <ivevlp$kdi$1@newscl01ah.mathworks.com> <ivf2lq$sq$1@newscl01ah.mathworks.com> <ivf45m$5qf$1@newscl01ah.mathworks.com> <ivfh09$gkk$1@newscl01ah.mathworks.com> Reply-To: "Skirt Zhang" <silence_qunzi@hotmail.com> NNTP-Posting-Host: www-04-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1310454428 6934 172.30.248.35 (12 Jul 2011 07:07:08 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Tue, 12 Jul 2011 07:07:08 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2029090 Xref: news.mathworks.com comp.soft-sys.matlab:735907 Hi Roger, Thanks a lot for your kind help. So I will use this randperm to generate my index sequence and then according to this index I need to calculate the product of any three values. Is there a clever way to address this issue? BIG thanks "Roger Stafford" wrote in message <ivfh09$gkk$1@newscl01ah.mathworks.com>... > "Skirt Zhang" <silence_qunzi@hotmail.com> wrote in message <ivf45m$5qf$1@newscl01ah.mathworks.com>... > > Hi Steven > > > > Thanks a lot for your quick and kindly reply. > > > > You are correct, it will take toooooo much time to compute, that's why I am think to extract the combinations, or only compute a subset of combinations. The subset may include only 1000 combinations from 2000*1999*19987/3 products. > > > > > > eg > > > > m = > > > > 6 7 8 1 2 3 4 5 > > > > if I select 3 elements there will be 56 combinations. However, I only want to obtain the 10/56 combinations, where the 10 products should be the most representative ones. How should I do this? > The best way to select random combinations of three distinct elements is to select random permutations of three distinct elements and that can be done using 'randperm'. For every combination of three there are six permutations of it, so the statistics would be equivalent. > > p = randperm(length(m)); > q = sort(p(1:3)); > s = m(q); % s is a randomly selected combination of three elements in m > > Repeat that in an appropriate for-loop the desired number of times. If you are worried about selecting the same combination twice, the odds of that ever happening for a thousand combinations out of a total of 2000*1999*1998/6 are about 1 in 2,666. Perhaps you could afford to neglect that possibility. > > Roger Stafford