[Scilab-users] Regarding simple numerical operations result display.

Stefan Du Rietz sdr at durietz.se
Tue Mar 19 11:10:04 CET 2013


On 2013-03-19 09:26, Dang, Christophe wrote:
--------------------
> Hello,
>
> De la part de Stefan Du Rietz
> Envoyé : lundi 18 mars 2013 17:23
>
>> But as usual there is a better (faster, simpler) solution without a
>> loop!
>>
>> // sort in reverse order and get indices
>> [ysort, k] = gsort(data(:, 2));
>
> Well, there are loops, hidden in gsort(), which is a quicksort.
>
> I think it is faster because you perform the loops only once.
>
> For optimisation in finding the highest -- or lowest -- values,
> you might find some ideas there:
>
> http://en.wikipedia.org/wiki/Selection_algorithm
>
> Best regards
>
But gsort is a built-in function (and very efficient):

-->typeof(gsort)
  ans  =
  fptr

I cite from your linked Wikipedia article:

"Selection can be reduced to sorting by sorting the list and then 
extracting the desired element. This method is efficient ..."

You should avoid code with loops because all lines in a loop are 
re-interpreted by Scilab in every round-trip -- it is therefore very 
slow. This is of course not the case with built-in functions.

I once used the datenum function in Scilab 4, which was not 
vectorized. It took many minutes to convert my large datevec matrix 
into a datenum vector. After my vectorization, it took a fractional 
second!

Regards
Stefan







More information about the users mailing list