Summary: Matlab Exercises
These exercises should help you to get used to vector and matrix notation in MATLAB,
indexing, matrix and element-wise operations. Do not use any loops (for, while) or if-else
statements. Find general solutions, not solutions for the given examples.
1. Create a vector x containing integer numbers from 1 to 100. Create a vector y
containing numbers 1, 0.9, 0.8, 0.7, . . . 0.1, 0 in this order.
2. From x create y containing first 25 elements of x, z containing elements of x with
indexes from 50 to 75 and w containing elements with even indexes.
3. Create matrix 3 by 3 with all ones. Create matrix 8 by 1 with all zeros. Create
matrix 5 by 2 with all elements equal to 0.37.
4. Create vector 1 by 25 containing random elements uniformly distributed in the
interval [-0.5, 0.5].
5. Create a vector x = [3, 1, 2, 5, 4]. From x create y containing the same elements
in the reverse order, find indices of elements greater than 2, create z containing
elements of x which are smaller than 4.
6. Create vector s containing elements of x sorted in an ascending order. Clear x from
the workspace. From s create back a vector with the same elements and in the same
order as in x.
Example: >> x = [3 1 2 5 4];
>> ...... % create s from x