Time for action - instantiating a cell array
1. To instantiate a cell array with the same data as the
projectile
structure above, we can use:
octave:44> projectile = {10.1, [1 0 0], "Cannonball"} projectile = { [1,1] = 10.1 [1,2] = 1 0 0 [1,3] = Cannonball }
The numbers in the square brackets are then the row indices and column indices, respectively.
2. To access a cell, you must use curly brackets:
octave:45> projectile{2} ans = 1 0 0
3. You can have two-dimensional cell arrays as well. For example:
octave:46> projectiles = {10.1, [1 0 0], "Cannonball"; 1.0, [0 0 0], "Cartridge"} projectile = { [1, 1] = 10.100 [2, 1] = 1 [1, 2] = 1 0 0 [2, 2] = 0 0 0 [1, 3] = Cannonball [2, 3] = Cartridge }
4. To access the values stored in the cell array, simply use:
octave:47> projectiles{2,3} ans = Cartridge
What just happened?
Command 44 instantiates a cell array with one row and three columns. The first cell contains the mass, the second cell the velocity, and the third cell the string "Cannonball...