[Scilab-users] any suggestion to make my Scilab code faster would be welcome:

kjubo kopac.jakub at gmail.com
Wed May 16 08:40:13 CEST 2018


Hello,

d = zeros(n,1);
for ii=1:n;
//    SqDist   = (X-X(i))^2 + (Y-Y(i))^2 + (Z-Z(i))^2;
    SqDist   = (X-X(ii)).*(X-X(ii)) + (Y-Y(ii)).*(Y-Y(ii)) +
(Z-Z(ii)).*(Z-Z(ii));
    SqDist(ii)= [];
    d(ii)    = sqrt(min(SqDist));
end; 

some comments:
* preallocate matrix
* avoid unnecessary assign of variables (this slow down scilab more than
expected)
* as seen in previous meesages here, use X*X instead of X^2

for me speed up factor is ~10

Regards.



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html



More information about the users mailing list