SUNY Geneseo Department of Mathematics
Wednesday, February 24
Math 230 02
Spring 2016
Prof. Doug Baldwin
arrayname = [ [row1]; [row2]; … ]
arrayname ( position )
arrayname ( row, column )
>> % Matrix of how many miles 3 people walked on 3 days
>> miles = [ [ 1.0, 1.0, 1.0 ]; [ 2.0, 2.0, 2.0]; [ 3.0, 3.0, 3.0 ] ]
miles =
1 1 1
2 2 2
3 3 3
>> % Fix the 1st person’s 2nd day distance
>> miles(1,2) = 10
miles =
1 10 1
2 2 2
3 3 3
>> % Linear indexing
>> miles( 5 )
ans =
2
>> % Convert to kilometers and (for no plausible reason) take the square roots
>> kms = miles .* 1.6
kms =
1.6000 16.0000 1.6000
3.2000 3.2000 3.2000
4.8000 4.8000 4.8000
>> sqrt( kms )
ans =
1.2649 4.0000 1.2649
1.7889 1.7889 1.7889
2.1909 2.1909 2.1909
>> vertices = [ [0, 0, 4]; [0, 3, 0] ]
vertices =
0 0 4
0 3 0
>> plot( vertices(1,:), vertices(2,:) )
>> % Oops, this didn’t close the triangle. Add a 4th vertex to do that
>> vertices(1,4) = 0
vertices =
0 0 4 0
0 3 0 0
>> plot( vertices(1,:), vertices(2,:) )
>> % Make axes extend far enough to make triangle visible
>> axis( [-1, 5, -1, 4 ] )
>> scale = [ [2, 0]; [0, 3] ]
scale =
2 0
0 3
>> vertices2 = scale * vertices
vertices2 =
0 0 8 0
0 9 0 0
>> hold on
>> plot( vertices2(1,:), vertices2(2,:), 'r' )
>> axis( [ -1, 9, -1, 10 ] )