Thanks Serge for your help,
 
Transforming a 3D array into a 2D allows to vectroize my problem in a simple 
way.
I have noted the true definition of the variance... We did not talk about the 
same actually..
 
Stéphane

________________________________

De: users-boun...@lists.scilab.org de la part de Serge Steer
Date: mar. 12/02/2013 17:50
À: International users mailing list for Scilab.
Objet : Re: [Scilab-users] Vectorization


You can try something like
// CALCULATE VARIANCE OVER LAST N POINTS 

Ni    =    100;
Nj    =    10;
Nk    =    10;

A     =    rand(Ni,Nj,Nk);    
tic;
A=matrix(A,Ni,-1);//transform A into a 2D array
D1=zeros(Ni-N+1,Nj*Nk);
for i=N:Ni, 
  D1(i-(N-1),:)=variance(A(i-(N-1):i,:),1);
end

D1=matrix(D1,-1,Nj,Nk); //Transform D1 into a 3D array
toc

Are you sure of your variance definition? For me if v is a vector the variance 
of v is computed by sqrt(sum( (v-mean(v))^2))

Serge Steer
INRIA
Le 12/02/2013 17:10, Stéphane Bécu a écrit :


        Hello,
         
        I have much difficulty to optimize my calculation. It consists of 
calculating the variance of a vector over last N elements . See the example in 
the attached file for a 3D matrix. With a PC under windows 7 and scilab 5.3, it 
needs 40 sec to calculate the variance for a 10*10*1000 matrix. This is too 
much long since I have much bigger files to work on.
         
        There must be a way to vectorize the problem but I do not see how ?
         
        Thanks in advance,
         
        Stéphane

         
        
        _______________________________________________
        users mailing list
        users@lists.scilab.org
        http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users

Reply via email to