SUNY Geneseo Department of Mathematics
Monday, April 11
Math 230 02
Spring 2016
Prof. Doug Baldwin
loop
...
plot 1st part (e.g., cell)
hold on
plot 2nd part (e.g., ball)
plot 3rd part (if any) ...
hold off
...
>> M = [ 10, 20, 30, 40; 100, 200, 300, 400; 1000, 2000, 3000, 4000; -1, -2, -3 -4 ]
M =
10 20 30 40
100 200 300 400
1000 2000 3000 4000
-1 -2 -3 -4
>> % Pick out central 2-x-2 submatrix
>> M( [6,7,10,11] )
ans =
200 2000 300 3000
>> M( [2:3], [2:3] )
ans =
200 300
2000 3000
>> M2 = M
M2 =
10 20 30 40
100 200 300 400
1000 2000 3000 4000
-1 -2 -3 -4
>> % swap 2nd and 3rd rows in M2
>> M2( [2,3], : ) = M2( [3,2], : )
M2 =
10 20 30 40
1000 2000 3000 4000
100 200 300 400
-1 -2 -3 -4
>> R = rand( 4 )
R =
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419
0.6324 0.9575 0.9572 0.4218
0.0975 0.9649 0.4854 0.9157
>> % all elements from R < 0.3
>> R < 0.3
ans =
1 1 1 0
0 0 0 1
0 0 0 0
1 0 0 0
>> R( R < 0.3 )
ans =
0.1270
0.0975
0.2785
0.1576
0.1419
>> mask = R < 0.3
mask =
1 1 1 0
0 0 0 1
0 0 0 0
1 0 0 0
>> R .* mask
ans =
0.1270 0.2785 0.1576 0
0 0 0 0.1419
0 0 0 0
0.0975 0 0 0
>> % Make all elements of R < 0.3 be -1
>> R( R < 0.3 ) = -1
R =
-1.0000 -1.0000 -1.0000 0.8003
0.9134 0.5469 0.9706 -1.0000
0.6324 0.9575 0.9572 0.4218
-1.0000 0.9649 0.4854 0.9157
>> M
M =
10 20 30 40
100 200 300 400
1000 2000 3000 4000
-1 -2 -3 -4
>> R = rand( 4 )
R =
0.7922 0.8491 0.7431 0.7060
0.9595 0.9340 0.3922 0.0318
0.6557 0.6787 0.6555 0.2769
0.0357 0.7577 0.1712 0.0462
>> R( R < 0.3 ) = M( R < 0.3 )
R =
1.0e+03 *
0.0008 0.0008 0.0007 0.0007
0.0010 0.0009 0.0004 0.4000
0.0007 0.0007 0.0007 4.0000
-0.0010 0.0008 -0.0030 -0.0040
>> load 'birdImage.mat'
>> imshow( bird )
>> bird( 1:10, 1:10 )
ans =
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
>> bird( 121:131, 121:131 )
ans =
254 255 255 255 255 255 254 254 255 251 255
255 255 255 255 254 253 251 250 255 245 248
255 255 255 254 253 251 249 248 255 253 249
255 255 255 255 253 252 250 249 252 248 249
255 255 255 255 255 255 254 253 251 243 249
254 255 255 255 255 255 255 254 243 255 250
255 255 255 255 255 254 253 252 241 254 189
255 255 255 255 253 251 249 248 250 191 87
248 255 255 239 255 255 248 255 192 90 17
255 239 248 255 253 253 241 204 94 29 0
250 248 255 252 251 255 209 111 27 0 0