4.4: Indexing Errors

Physical Modeling in MATLAB · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    4.4: Indexing Errors

    An index can be any kind of expression, but the value of the expression has to be a positive integer, and it has to be less than or equal to the length of the vector. If it’s zero or negative, you’ll get an error:

    >> Y(0)
    Array indices must be positive integers or logical values.

    If it’s not an integer, you get an error:

    >> Y(1.5)
    Array indices must be positive integers or logical values.

    If the index is too big, you also get an error:

    >> Y(5)
    Index exceeds the number of array elements (4).

    The error messages use the word array rather than matrix, but they mean the same thing, at least for now.


    This page titled 4.4: Indexing Errors was last modified on Thu, 17 Nov 2022 18:18:27 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Allen B. Downey (Green Tea Press) via source content that was edited to the style and standards of the LibreTexts platform.