SUNY Geneseo Department of Mathematics
Monday, February 8
Math 230 02
Spring 2016
Prof. Doug Baldwin
array1( array2 )
array1 = [ array2, array3,
… ]
end
keyword means last position in an array>> % Create some vectors
>> v = 1:5
v =
1 2 3 4 5
>> w = 10:10:100
w =
10 20 30 40 50 60 70 80 90 100
>> % First 3 elements in w
>> w(1:3)
ans =
10 20 30
>> w([1:3])
ans =
10 20 30
>> % Last 3 elements of w
>> w(end-3:end)
ans =
70 80 90 100
>> % Oops, that was the last 4 elements
>> w(end-2:end)
ans =
80 90 100
>> % Reverse w
>> wReverse = w( end:-1:1 )
wReverse =
100 90 80 70 60 50 40 30 20 10
>> % Delete 1st element of v
>> v
v =
1 2 3 4 5
>> v(1) = []
v =
2 3 4 5
>> % Delete 2nd and 3rd elements of v
>> v(2,3) = []
{Subscripted assignment dimension mismatch.}
% Oops, forgot the square brackets that make the list of indices a vector
>> v([2,3]) = []
v =
2 5
>> % Concatenate v to itself
>> [ v, v ]
ans =
2 5 2 5
>> [ v, v, v, v ]
ans =
2 5 2 5 2 5 2 5
>> v4 = [ v, v, v, v ]
v4 =
2 5 2 5 2 5 2 5
>> v12 = [ v4, v4, v4 ]
v12 =
Columns 1 through 11
2 5 2 5 2 5 2 5 2 5 2
Columns 12 through 22
5 2 5 2 5 2 5 2 5 2 5
Columns 23 through 24
2 5
>> v50 = [ v12, v12, v12, v12, v, v ]
v50 =
Columns 1 through 11
2 5 2 5 2 5 2 5 2 5 2
Columns 12 through 22
5 2 5 2 5 2 5 2 5 2 5
Columns 23 through 33
2 5 2 5 2 5 2 5 2 5 2
Columns 34 through 44
5 2 5 2 5 2 5 2 5 2 5
Columns 45 through 55
2 5 2 5 2 5 2 5 2 5 2
Columns 56 through 66
5 2 5 2 5 2 5 2 5 2 5
Columns 67 through 77
2 5 2 5 2 5 2 5 2 5 2
Columns 78 through 88
5 2 5 2 5 2 5 2 5 2 5
Columns 89 through 99
2 5 2 5 2 5 2 5 2 5 2
Column 100
5
>> % Concatenation and deletion are particularly helpful for working with strings
>> % (which are just vectors of characters)
>> first = 'Jill'
first =
Jill
>> last = 'Smith'
last =
Smith
>> full = [first,last]
full =
JillSmith
>> full = [first,' ',last]
full =
Jill Smith
>> vowels = full([2,8])
vowels =
ii