See other catalogues for
The MathWorks
You may also be interested in
Text version of the page
| | | | | | | | | | | | | | | |
| | | |
| | | Matrix Indexing | | |
| | | |
| | | B = A; B(1:3:16) = -10 B= | | |
| | | |
| | | | | | | | | | | | -10 | 2 | 3 | -10 | | | | 5 | 11 | -10 | 8 | | | | 9 | -10 | 6 | 12 | | | | -10 | 14 | 15 | -10 | | | | | | | | | | | |
| | | |
| | | MATLAB supports a type of array indexing that uses one array as the index into another array. You can base this type of indexing on either the values or the positions of elements in the indexing array. Here is an example of value-based indexing where array B indexes into elements 1, 3, 6, 7,and 10 of array A.Inthiscase, the numeric values of array B designate the intended elements of A: A = 5:5:50 A= 5101520253035404550 B=[1 36710]; A(B) ans = 51530 3550 | | |
| | | |
| | | The end Keyword MATLAB provides the keyword end to designate the last element in a particular dimension of an array. This keyword can be useful in instances where your program does not know how many rows or columns there are in a matrix. You can replace the expression in the previous example with B(1:3:end) = -10 | | |
| | | |
| | | Note The keyword end has several meanings in MATLAB. It can be used as explained above, or to terminate a conditional block of code such as if and for blocks, or to terminate a nested function. | | |
| | | |
| | | 1-21 | | |
| | | |
| | | | | | | | | | | | | | | |