Structures and cell arrays

In many real life applications, we have to work with objects that are described by many different types of variables. For example, if we wish to describe the motion of a projectile, it would be useful to know its mass (a scalar), current velocity (a vector), type (a string), and so forth. In Octave, you can instantiate a single variable that contains all this information. These types of variables are named structures and cell arrays.

Structures

A structure in Octave is like a structure in C—it has a name, for example projectile, and contains a set of fields3 that each has a name, as shown in the following figure:

We can refer to the individual structure field using the. character:

structurename.fieldname ...

Get GNU Octave now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.