next up previous contents
Next: Plotting a vector or Up: Matrices as physiological traces Previous: Access to the components   Contents

Access to the components of a vector: an example

We are interested now in detecting sequences of the signal whose value increases. We begin with a random vector and we will use a Boolean vector coupled with it to detect upward sequences (a Boolean vector is a vector composed by true and false values: %T and %F).


-->randvector = rand(1:10)             // generate random vector
 randvector  =
 
 
         column 1 to 5
 
!   0.2113249    0.7560439    0.0002211    0.3303271    0.6653811 !
 
         column  6 to 10
 
!   0.6283918    0.8497452    0.6857310    0.8782165    0.0683740 !

By using the commands described in the previous section


-->checkvector = randvector(2:$) - randvector (1:$-1)
 checkvector  =
 
 
         column 1 to 5
 
!   0.5447190  - 0.7558227    0.3301060    0.3350540  - 0.0369893 !
 
         column 6 to 9
 
!   0.2213534  - 0.1640142    0.1924855  - 0.8098424 !

We are going to convert `checkvector' in a Boolean vector (`checkvectorbool') containing %T if `checkvector' is positive, which indicates that we face an increasing sequence, and %F in any other case.


-->checkvectorbool = checkvector>0       //creates boolean vector
 checkvectorbool  =
 
! T F T T F T F T F !

Since `checkvector' describes differences, we add at the first position a false value (the first value, of course, has not increased its value). A Boolean vector acts like a vector of `ones' and `zeros' which allows the extraction of values from a vector


-->checkvectorbool = [%F, checkvectorbool] // adds %F at the beginning
 checkvectorbool  =
 
! F T F T T F T F T F !

-->result = randvector .* checkvectorbool  // extraction of values
 result  =
 
 
         column 1 to 8
 
!   0.    0.7560439    0.    0.3303271    0.6653811    0.    0.8497452    0. !
 
         column  9 to 10
 
!   0.8782165    0. !
 
-->check = [randvector;result]'         // we transpose it to show it better
 check  =
 
!   0.2113249    0.        !
!   0.7560439    0.7560439 !
!   0.0002211    0.        !
!   0.3303271    0.3303271 !
!   0.6653811    0.6653811 !
!   0.6283918    0.        !
!   0.8497452    0.8497452 !
!   0.6857310    0.        !
!   0.8782165    0.8782165 !
!   0.0683740    0.        !

The first column of `check' is the original vector (`randvector'), the second one is the output (`result'). In summary, we detected the values that are greater than its precedent value and we erased those values not satisfying this property. To do it, we used a Boolean vector which is produced by checking globally the vector with a condition. We have not had to access the length of the vector and the same procedure could have been used for very long vectors or real signals.


next up previous contents
Next: Plotting a vector or Up: Matrices as physiological traces Previous: Access to the components   Contents
je 2006-10-13