Lecture 2 Computer Programming
Lecture 2 Computer Programming
2) >>linspace (2,3,6);
A vector (2:0.2:3) will consist of a range of numbers from 2 to 3 with a 0.2
interval between each consecutive number. This will result in 6 numbers.
4) >>vec= randi(1,10);
>>vec (1:2: end)
>>vec =randi(1,10);
>>vec (1:2: end);
The expression above will index the odd or even indices for any length of
vector.
5) Size. This is because it tells you both the rows & columns.
6) If you want to know the number of elements, you would use length. If you
want to figure out whether it is a row or column vector, you would use size.
8) >>vec = 1:3:16;
a)>>vec(end);
b)>>vec(numel(vec));
c)>>vec(length(vec));
d)>>v=fliplr(vec);
>>v (1);
9) >>mat=rand (3,5);
>>mat (3, :)= []
The expression mat = rand(3,5) creates a random 3 by 5 matrix mat and
mat(3,:) deletes the 3rd row.