[Scilab-users] function find()

sgougeon at free.fr sgougeon at free.fr
Tue May 27 17:40:19 CEST 2014


Hello,

>// initialisation
>diam = 0.2;
>nd = 10;
>etat = (rand(nd,2) -0.5)*4;
>distance = zeros(nd,nd);
>//compute distance matrix
>for i = 1:(nd-1)
>     for j = (i+1):nd
>         distance(i,j) = sqrt((etat(i,1)-etat(j,1))**2+(etat(i,2)-etat(j,2)**2));
>     end
>end

You may do without explicit nested loops:

[X,Y] = meshgrid(etat(:,1), etat(:,2));
distance = sqrt((X-X.').^2 + (Y-Y.').^2)

Samuel



More information about the users mailing list