Practical 3: Arrays
Arrays
Array Subscripts
Subscripts, or indices, are used to refer to elements at a specified location in an array.
In MATLAB, A(i) is the th element in the array A and is the index (or position).
You can refer to one or more elements and use these to create new scalar variables or sub-arrays.
> Type in the following code and decide which commands create scalars and which arrays. > Check the output and determine the process by which the elements have been selected: A= linspace(5,100,20) A(1) A(7) A(3:6) > Now create two new sub-arrays of A as follows: a4 = A(1:2:13) a5 = A(8:-3:2) > Recall the elements in the sub-arrays as follows: a4(2) a5(1:3) |