gsort — sorting by quick sort agorithm
[B [,k]]=gsort(A) [B [,k]]=gsort(A,option) [B [,k]]=gsort(A,option,direction)
a real,an integer or a character string vector/matrix.
a character string. It gives the type of sort to perform:
'r' : each column of A is sorted
'c': each row of A is sorted
'g': all elements of A are sorted. It is the default value.
'lr': lexicographic sort of the rows of A
'lc': lexicographic sort of the columns of A
a character string. It gives the ordering direction:
'i' stand for increasing and
'd' for decreasing order.
an array with same type and dimensions as A.
a real array with integer values and same dimensions
as A. Contains the origin indices.
gsort implements a "quick sort" algorithm for
various data types.
B=gsort(A,'g'),
B=gsort(A,'g','d') and
B=gsort(A) sort the elements of the array
A, seen as A(:) in a decreasing order.
B=gsort(A,'g','i') sort the elements of the array
A in the increasing order.
B=gsort(A,'lr') sorts the rows of
A in lexical decreasing order.
B is obtained by a permutation of the rows
of matrix A in such a way that the rows of
B verify
B(i,:)>=B(j,:) if
i<j.
B=gsort(A,'lr','i') works similarily
for increasing lexical order.
B=gsort(A,'lc') sorts the columns of
A in lexical decreasing order.
B is obtained by a permutation of the columns
of matrix A in such a way that the columns of
B verify
B(:,i)>=B(:,j) if
i<j.
B=gsort(A,'lc','i') works similarily
for increasing lexical order.
If required the second return argument k
contains the indices of the sorted values in
A. If [B,k]=gsort(A,'g') one
has B==A(k). The
algorithme preserve the relative order of records with equal
values.
When v is complex, the elements are sorted by
magnitude, i.e., abs(v) . Only 'g' as second argument
is managed with complex.
if v have %nan or
%inf as elements. gsort places these at the beginning
with 'i' or at the end with 'd'
argument.
alr=[1,2,2;
1,2,1;
1,1,2;
1,1,1];
[alr1,k]=gsort(alr,'lr','i')
[alr1,k]=gsort(alr,'lc','i')
v=int32(alr)
gsort(v)
gsort(v,'lr','i')
gsort(v,'lc','i')
v=['Scilab' '2.6'
'Scilab' '2.7'
'Scicos' '2.7'
'Scilab' '3.1'
'Scicos' '3.1'
'Scicos' '4.0'
'Scilab' '4.0']
gsort(v,'lr','i')
gsort(v,'lc','i')