01.09.2014 Views

Programming with SCILAB (pdf)

Programming with SCILAB (pdf)

Programming with SCILAB (pdf)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

! 0. 2. 2. 4. 4. 4. 4. 5. 6. 9. !<br />

Of course, you don’t need to write your own function for sorting vectors of data since<br />

<strong>SCILAB</strong> already provides function gsort for this purpose, e.g.,<br />

-->gsort(u,'g','i')<br />

ans =<br />

! 0. 2. 2. 4. 4. 4. 4. 5. 6. 9. !<br />

However, a function like MySort, shown above, can be used for programming an<br />

increasing-order sort in other computer languages that do not operate based on<br />

matrices, e.g., Visual Basic or Fortran.<br />

Notice that the function gsort can produce a decreasing order sort by using simply:<br />

-->gsort(u)<br />

ans =<br />

! 9. 6. 5. 4. 4. 4. 4. 2. 2. 0. !<br />

Function MySort can be modified to perform a decreasing order sort if the line if<br />

v(i)>v(j) then is modified to read if v(i)v(j) then<br />

temp = v(i)<br />

v(i) = v(j)<br />

v(j) = temp<br />

end<br />

end<br />

end<br />

else<br />

for i = 1:n-1<br />

for j = i+1:n<br />

if v(i)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!