next up previous contents
Next: Measuring curves Up: Operating with arrays as Previous: Operating with arrays as   Contents

Global operation on vectors

Clinical neurophysiologists work on signals of very different length. They recognize patterns or make measurements on these signals. They tend to see each trace or even each page of the recording as a unit. The syntax of Scilab affords the use of simple expressions which can mimic some of these processes.

We are going to work on a vector of random values


-->base=rand(1,10);

-->base'
 ans  =

!    .5608486 !
!    .6623569 !
!    .7263507 !
!    .1985144 !
!    .5442573 !
!    .2320748 !
!    .2312237 !
!    .2164633 !
!    .8833888 !
!    .6525135 !

We can operate with a lot of global instructions acting on the whole vector


-->sum(base)
 ans  =

    4.907992

-->prod(base)
 ans  =

     .0001952

-->mean(base)
 ans  =

     .4907992

-->median(base)
 ans  =

     .5525530

-->st_deviation(base)
 ans  =

     .2512121

These commands can be combined with other commands


-->sum(abs(base))
 ans  =

    4.907992
They can return sets of values; for instance, if we are interested in locating the minimum or the maximum of a trace, we are not only interested in finding the value but usually we want to know its position too


-->[minbase, minbasendx] = min(base)
 minbasendx  =

    4.
 minbase  =

     .1985144

-->[maxbase, maxbasendx] = max(base)
 maxbasendx  =

    9.
 maxbase  =

     .8833888
Scilab returns not only the value but also the position (i.e., the index of the value within the vector) where it was found. Even more generally, in Scilab functions are capable or returning several variables that can also be vectors.

-->[baseord , oldndx]=sort(base)

 oldndx  =

!   9.    3.    2.    10.    1.    5.    6.    7.    8.    4. !
 baseord  =


         column 1 to 5

!    .8833888     .7263507     .6623569     .6525135     .5608486 !

         column  6 to 10

!    .5442573     .2320748     .2312237     .2164633     .1985144 !

We get two vectors: `baseord' which is composed by the components of `base' in decreasing order and `oldndx' which indicates where the values were situated before the process of ordering. Notice that the first and the last values are those which were obtained by using `max' and `min' and that their positions are coincident with those obtained by the use of these commands.

Functions are capable of returning two variables that can be vectors too.


next up previous contents
Next: Measuring curves Up: Operating with arrays as Previous: Operating with arrays as   Contents
je 2006-10-13