Geoscience Reference
In-Depth Information
ans 1x4 32 double
b 1x1 8 double
Note that by default MATLAB is case sensitive, i.e., A and a can dei ne two
dif erent variables. In this context, it is recommended that capital letters be
used for arrays that have two dimensions or more and lower-case letters
for one-dimensional arrays (or vectors) and for scalars. However, it is
also common to use variables with mixed large and small letters. h is is
particularly important when using descriptive variable names, i.e., variables
whose names contain information concerning their meaning or purpose,
such as the variable CatchmentSize , rather than a single-character variable a .
We could now delete the contents of the variable ans by typing
Movie
2.2
clear ans
Next, we will learn how specii c array elements can be accessed or exchanged.
Typing
A(3,2)
simply yields the array element located in the third row and second column,
which is 9 . h e array indexing therefore follows the rule (row, column) . We
can use this to replace single or multiple array elements. As an example we
type
A(3,2) = 30
to replace the element A(3,2) by 30 and to display the entire array.
A =
2 4 3 7
9 3 -1 2
1 30 3 7
6 6 3 -2
If we wish to replace several elements at one time, we can use the colon
operator . Typing
A(3,1:4) = [1 3 3 5]
or
A(3,:) = [1 3 3 5]
replaces all elements of the third row of the array A . h e colon operator also
has several other uses in MATLAB, for instance as a shortcut for entering
array elements such as
Search WWH ::




Custom Search