|
On 6/19/2012 5:43 PM, besbesmany besbesmany wrote:
> I use large dataset , this is sample mtrices
> i want to make code more optimize by vectorization or decreses, for
> loops used
>
> A = [ 1 2 3; 4 5 2;2 4 5;3 5 1;3 2 1];
> B = [ .5 1.5 .3;.4 .6 .1;.4 .2 .3;.9 .6 .8;.5 .7 .1 ];
>
> [M N]= size(B);
> [~, F]= size(B);
> out = zeros(M,N-1);
>
> for m = 1:M
> for n = 1:N-1
> for ne=1:F
> out(m,n)=out(m,n) + B(A(m,ne),n);
> end%ne
> end%n
> end%m
One alternative...may be quicker way to get into shape but didn't see it
otomh. If your arrays are large the ordering to use normal stride
should help...
C=zeros(M,N,3);
for i1=1:N
for i2=1:M
C(i2,i1,:)=B(A(i2,1:F),i1);
end
end
out=sum(C,3);
--
|