|
From: | Rob Mahurin |
Subject: | Re: vectorise matrix slice extraction |
Date: | Fri, 27 Feb 2009 11:25:32 -0500 |
On Feb 27, 2009, at 10:58 AM, Francesco Potorti` wrote:
Is there a way to efficiently remove the for loop in this assignment?for jj = length(pple):-1:1 llk(:,:,:,jj) = ll(:,:,:,pple(jj),tple(jj)); endforMaybe try s = size(ll); s1 = 1:s(1); # etc. llk( s1,s2,s3, 1:numel(pple) ) = reshape( ll(s1,s2,s3, pple, tple), [s(1:3), numel(pple)] );This would be equivalent to llk = ll(:,:,:,pple,tple); but it does not work. Take this as an example:
Right, so it would. You could do the offsetting yourself, as in [i,j] = find(eye(2)); eye(2)(i + 2*(j-1)) which returns [1;1]. So in your case maybe s = size(ll); ll_tmp = reshape(ll, [s(1:3), prod(s(4:5))]); llk = ll_tmp(:,:,:, pple + s(4)*(tple-1) ); clear ll_tmp; ? Cheers, Rob -- Rob Mahurin Department of Physics and Astronomy University of Tennessee 865 207 2594 Knoxville, TN 37996 address@hidden
[Prev in Thread] | Current Thread | [Next in Thread] |