SUNY Geneseo Department of Mathematics
Friday, February 26
Math 230 02
Spring 2016
Prof. Doug Baldwin
horzcat
, vertcat
and errors when numbers of rows/columns
don’t agree>> M = [ [1 2 3]; [4 5 6]; [7 8 9] ]
M =
1 2 3
4 5 6
7 8 9
>> N = [ [ 10 11 12 ]; [13 14 15]; [16 17 18] ]
N =
10 11 12
13 14 15
16 17 18
>> [ M , N ]
ans =
1 2 3 10 11 12
4 5 6 13 14 15
7 8 9 16 17 18
>> horzcat( M, N )
ans =
1 2 3 10 11 12
4 5 6 13 14 15
7 8 9 16 17 18
meshgrid
>> % subtraction table, x - y, x between 1 and 5, y between -1 and 3
>> x = 1:5
x =
1 2 3 4 5
>> y = -1:3
y =
-1 0 1 2 3
>> meshgrid( x, y )
ans =
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
>> [ Xtable, Ytable ] = meshgrid( x, y )
Xtable =
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Ytable =
-1 -1 -1 -1 -1
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
>> Xtable - Ytable
ans =
2 3 4 5 6
1 2 3 4 5
0 1 2 3 4
-1 0 1 2 3
-2 -1 0 1 2
>> % Change which of x and y are vertical vs horizontal?
>> [ Xtable, Ytable ] = meshgrid( y, x )
Xtable =
-1 0 1 2 3
-1 0 1 2 3
-1 0 1 2 3
-1 0 1 2 3
-1 0 1 2 3
Ytable =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
>> [ Ytable, Xtable ] = meshgrid( y, x )
Ytable =
-1 0 1 2 3
-1 0 1 2 3
-1 0 1 2 3
-1 0 1 2 3
-1 0 1 2 3
Xtable =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5