Path: news.mathworks.com!not-for-mail
From: "Anthony Hopf" <anthony.hopf@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Randperm, Randi, and Shuffle
Date: Tue, 2 Nov 2010 22:02:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <iaq1os$sak$1@fred.mathworks.com>
Reply-To: "Anthony Hopf" <anthony.hopf@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1288735324 29012 172.30.248.37 (2 Nov 2010 22:02:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 2 Nov 2010 22:02:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1899184
Xref: news.mathworks.com comp.soft-sys.matlab:683359

I am trying to replace the following code:

[rix riy riz] = ind2sub(sampbox,randi(myrandistr,prod(sampbox),SPtemp,1));

where sampbox can get large ( [1100         200         200]) and SPtemp can be 125e3.  This is not the case all of the time, but it is definitely bogs down the process.

I want to replace my current code because it seems to show a bias when I plot out the locations it is picking within the 3d space.

Originally I wanted to replace this piece of code with randperm, but it was incredibly slow.  Luckily I found Jan's addition to FEX called Shuttle.  It seemed to really fit the bill because I would specify the number of NOut within his function.  Orders of magnitude faster than randperm for sure.  

Problem is now Shuffle is fast, 0.32sec for the above extreme, but not as fast as randi, 0.014 for the same case.  

This is the code I am using with Shuffle:

        randpts = Shuffle(prod(sampbox),'index',SPtemp);
        [rix riy riz] = ind2sub(sampbox,randpts);

Thank you

Anthony