Financial Toolbox |
 |
Referencing Matrix Elements
To reference specific matrix elements use (row, column) notation. For example,
Bonds(1,2)
ans =
0.06
Cash(3)
ans =
5280.00
You can enlarge matrices using small matrices or vectors as elements. For example,
AddBond = [1000 0.065 2];
Bonds = [Bonds; AddBond]
adds another row to the matrix and creates
Bonds =
1000 0.06 2
500 0.055 4
1000 0.065 2
Likewise,
Prices = [987.50
475.00
995.00]
Bonds = [Prices, Bonds]
adds another column and creates
Bonds =
987.50 1000 0.06 2
475.00 500 0.055 4
995.00 1000 0.065 2
Finally, the colon (:
) is important in generating and referencing matrix elements. For example, to reference the par value, coupon rate, and coupon frequency of the second bond.
BondItems = Bonds(2, 2:4)
BondItems =
500.00 0.055 4
| Using Matrix Functions for Finance | | Transposing Matrices |  |