Path: news.mathworks.com!not-for-mail
From: "Sven " <sven.holcombe@gmail.deleteme.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Voxel loop optimisation
Date: Tue, 1 Apr 2008 00:35:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 24
Message-ID: <fsrvvo$7rn$1@fred.mathworks.com>
References: <fsevre$cg7$1@fred.mathworks.com> <fsfdem$ait$1@fred.mathworks.com>
Reply-To: "Sven " <sven.holcombe@gmail.deleteme.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1207010104 8055 172.30.248.35 (1 Apr 2008 00:35:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 1 Apr 2008 00:35:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1326470
Xref: news.mathworks.com comp.soft-sys.matlab:460220


"Phil Goddard" <philgoddardNOSPAM@telus.net> wrote in
message <fsfdem$ait$1@fred.mathworks.com>...
> You could use ARRAYFUN in conjunction with an appropriate 
> function handle, i.e.
> 
> fh = @(idx,page) rc(idx,:,page)';
> myIndexed2d = cell2mat(arrayfun(fh,idxs,1:length
> (idxs),'UniformOutput',false))';
> 
> However, if you're looking for speed, then in newer 
> versions of MATLAB (at least since since R2006a) the loop 
> is likely to be faster for the purely numeric data that 
> you're manipulating.
> 
> Phil.

Thanks Phil and Peter.
The real voxel data I'm working with is much larger than
3x3x3, so the sub2ind method ends up taking too much memory
to build the index arrays.  The arrayfun method is new to me
so I'll try this and check its speed compared to the loop.

Thanks again,
Sven.