Let's define a vector
-->stepvector = [zeros(1,5), ones(1,5)] stepvector = ! 0. 0. 0. 0. 0. 1. 1. 1. 1. 1. !`zeros(n,m)' produces a matrix of n rows and m columns or zeros, `ones(n,m)' does the same with ones, the `comma' chains both in rows and the brackets build the vector.
To extract its individual components we can use the next commands
-->stepvector(5)
ans =
0.
-->stepvector(6)
ans =
1.
-->stepvector(4:7)
ans =
! 0. 0. 1. 1. !
We can eliminate some components
->length(stepvector)
ans =
10.
-->stepvector(4:7)=[]
stepvector =
! 0. 0. 0. 1. 1. 1. !
-->length(stepvector)
ans =
6.
Or we can insert some new components
-->stepvector = [stepvector(1:3), [2,2,2,2],stepvector(4:6)] stepvector = ! 0. 0. 0. 2. 2. 2. 2. 1. 1. 1. !To access the last component of a vector we could do
-->stepvector(length(stepvector))
ans =
1.
But we also have an interesting operator: `$'
-->stepvector($)
ans =
1.
which enables to select elements from the end
-->stepvector($-4)
ans =
2.
We have extracted, inserted and deleted internal values of a vector; now we are going to use these methods for some practical objectives.