Time for action – instantiating a structure

  1. To set the projectile mass, we can use:
    octave:32>projectile.mass = 10.1
    
    projectile =
    {
    mass = 10.100
    }
    
  2. The velocity field is set in a similar fashion:
    octave:33>projectile.velocity = [1 0 0]
    
    projectile =
    {
    mass = 10.100
    velocity =
       0    0   
    }
    
  3. We can also set the text field as usual:
    octave:34>projectile.type = "Cannonball"
    
    projectile =
    {
    mass = 10.100
    velocity =
    	1    0    0
    type = Cannonball 
    }
    

and so on for position and whatever else could be relevant.

What just happened?

Command 32 instantiates a structure variable with the name projectile by assigning a field named mass the value 10.100. At this point, the structure variable only contains this one field.

In Commands 33 and 34, we then add two new fields to ...

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.