|
From: | William Krekeler |
Subject: | vectorization help |
Date: | Mon, 3 Oct 2011 17:26:51 +0000 |
I'm trying to vectorize an operation on a three dimensional
matrix and would appreciate suggestions for improvements. I included an example
of the original code and my poor initial attempt at vectorization. The input
matrices are random to provide an easily replicable test case. The alternative
vectorization case results in the wrong size matrix as a cell array, and before
calls to cell2mat and reshape to fix the size my alternative is slower than my
original code set. % original code set RC = rand( 1, 448 ); Cube = rand( 160,512,448 ); tic for lamda = 1: size( Cube, 3 ) Cube(:,:,lamda) = (
RC(lamda)./ squeeze( Cube(:,:,lamda) ) ); end toc % incomplete vectorization attempt tic new = arrayfun( @(i)(bsxfun(@rdivide,RC(i),Cube(:,:,i))),
1:size(Cube,3), 'UniformOutput',false); toc new is not equal to Cube in this case. Please suggest
better vectorization code or other improvements. William Krekeler |
[Prev in Thread] | Current Thread | [Next in Thread] |