Graphics Programs Reference

In-Depth Information

>> [a a(a)]

ans =

1

2

3

1

4

7

4

5

6

2

5

8

7

8

9

3

6

9

The colon symbol can be used as a single index to a matrix. Continuing

the previous example, if you type

a(:)

matlab interprets this as the columns of the
a
-matrix successively

strung out in a single long column:

>> a(:)

ans =

1

4

7

2

5

8

3

6

9

3.5 End as a subscript

To access the last element of a matrix along a given dimension, use
end

as a subscript (matlab version 5 or later). This allows you to go to the

final element without knowing in advance how big the matrix is. For

example:

>> q = 4:10

q=

4

5

6

7

8

9

10

>> q(end)

ans =

10

>> q(end-4:end)

ans =

6

7

8

9

10

>> q(end-2:end)

ans =

8

9

10

This technique works for two-dimensional matrices as well: