• Matlab TutorialsNo Comments

    default thumbnail

    The element in row i and column j of A is denoted by A(i,j). For , A(4,2) is the number in the fourth row and second column. For our magic square, A(4,2) is 15. So it is possible to compute the of the elements in the fourth column of A by typing

    A(1,4) + A(2,4) + A(3,4) + A(4,4)

    This produces

    ans =
         34

    but is not the most elegant way of summing a column.

    It is also possible to refer to the elements of a with a single subscript, A(k). This is the usual way of referencing row and column vectors. But it can also apply to a fully two-dimensional , in which case the is regarded as one long column vector formed from the columns of the original . So, for our magic square, A(8) is another way of referring to the value 15 stored in A(4,2).

    you try to use the value of an element outside of the matrix, it is an .

    t = A(4,5)

    Index exceeds matrix dimensions.
    On the other hand, if you store a value in an element outside of the matrix, the increases to accommodate the newcomer.

    X = A;
    X(4,5) = 17
    X =
        16     3     2    13     0
         5    10    11     8     0
         9     6     7    12     0
         4    15    14     1    17
    You might also be interested in :  quit

    Comment closed!