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

Heinz Nabielek heinznabielek at me.com
Wed May 16 19:58:03 CEST 2018


Histogram shows distribution of d and comparison with my model prediction.
Heinz


> On 16.05.2018, at 19:44, Heinz Nabielek <heinznabielek at me.com> wrote:
> 
> Yes- factor 10. Great many thanks for all the help.
> Heinz
> 
>> On 16.05.2018, at 08:40, kjubo <kopac.jakub at gmail.com> wrote:
>> 
>> 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.
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20180516/02bc19e7/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-1.tiff
Type: image/tiff
Size: 51494 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20180516/02bc19e7/attachment.tiff>


More information about the users mailing list