Geoscience Reference
In-Depth Information
ans =
3
which tells us the dimension of the largest array only. Hence length is
normally used to determine the length of a one-dimensional array (or
vector), such the evenly-spaced time axis c that was created in Section 2.3.
MATLAB uses a matrix-style indexing of arrays with the (1,1) element
being located in the upper-let corner of arrays. Other types of data that are
to be imported into MATLAB may follow a dif erent indexing convention.
As an example, digital terrain models (introduced in Chapter 7.3 to 7.5)
ot en have a dif erent way of indexing and therefore need to be l ipped in an
up-down direction or, in other words, about a horizontal axis. Alternatively,
we can l ip arrays in a let -right direction (i.e., about a vertical axis). We can
do this by using flipud for l ipping in an up-down direction and fliplr for
l ipping in a let -right direction
F = flipud(A)
F = fliplr(A)
yielding
F =
9 3 -1
2 4 3
F =
3 4 2
-1 3 9
In more complex examples we can use circshift(A,K,dim) to circularly shit
(i.e., rotate) arrays by K positions along the dimension dim . As an example we
can shit the array A by 1 position along the 2nd dimension (i.e., along the
rows) by typing
G = circshift(A,1,2)
which yields
G =
3 2 4
-1 9 3
We can also use reshape(A,[m n]) to completely reshape the array. h e result
is an m -by- n array H whose elements are taken column-wise from A . As an
example we create a 3-by-2 array from A by typing
H = reshape(A,[3 2])
Search WWH ::




Custom Search