SUNY Geneseo Department of Mathematics
Wednesday, February 4
Math 230 02
Spring 2015
Prof. Doug Baldwin
% 5-by-5 linearly spaced values between 0 to 5
>> m = linspace(0,5,5)
m =
0 1.2500 2.5000 3.7500 5.0000
>> m = [ linspace(0,5,5); linspace(0,5,5); linspace(0,5,5); linspace(0,5,5); linspace(0,5,5) ]
m =
0 1.2500 2.5000 3.7500 5.0000
0 1.2500 2.5000 3.7500 5.0000
0 1.2500 2.5000 3.7500 5.0000
0 1.2500 2.5000 3.7500 5.0000
0 1.2500 2.5000 3.7500 5.0000
% Not really what we wanted...
>> values = linspace(0,5,25)
values =
Columns 1 through 6
0 0.2083 0.4167 0.6250 0.8333 1.0417
Columns 7 through 12
1.2500 1.4583 1.6667 1.8750 2.0833 2.2917
Columns 13 through 18
2.5000 2.7083 2.9167 3.1250 3.3333 3.5417
Columns 19 through 24
3.7500 3.9583 4.1667 4.3750 4.5833 4.7917
Column 25
5.0000
>> reshape( values, 5, 5 )
ans =
0 1.0417 2.0833 3.1250 4.1667
0.2083 1.2500 2.2917 3.3333 4.3750
0.4167 1.4583 2.5000 3.5417 4.5833
0.6250 1.6667 2.7083 3.7500 4.7917
0.8333 1.8750 2.9167 3.9583 5.0000
% We want values to progress across rows, not down columns
>> ans'
ans =
0 0.2083 0.4167 0.6250 0.8333
1.0417 1.2500 1.4583 1.6667 1.8750
2.0833 2.2917 2.5000 2.7083 2.9167
3.1250 3.3333 3.5417 3.7500 3.9583
4.1667 4.3750 4.5833 4.7917 5.0000
>> % Indexing -- picking one or more values out of a matrix or vector
>> m = ans;
>> values(17)
ans =
3.3333
>> values(15:19)
ans =
2.9167 3.1250 3.3333 3.5417 3.7500
>> values( [3 8 12 2 3] )
ans =
0.4167 1.4583 2.2917 0.2083 0.4167
>> m
m =
0 0.2083 0.4167 0.6250 0.8333
1.0417 1.2500 1.4583 1.6667 1.8750
2.0833 2.2917 2.5000 2.7083 2.9167
3.1250 3.3333 3.5417 3.7500 3.9583
4.1667 4.3750 4.5833 4.7917 5.0000
>> m( 15:19 )
ans =
4.5833 0.6250 1.6667 2.7083 3.7500
>> m( 3, 3 )
ans =
2.5000
>> m( 4:5, 4:5 )
ans =
3.7500 3.9583
4.7917 5.0000