mp_table_subclass

class mp_table_subclass

mp_table_subclass - Class that acts like a table but isn’t one.

Addresses two issues with inheriting from table classes (table) or mp_table).

  1. In MATLAB, table is a sealed class, so you cannot inherit from it. You can, however, use a subclass of mp_table, but that can result in the next issue under Octave.

  2. While nesting of tables works just fine in general, when using mp_table in Octave (at least up through 8.4.0), you cannot nest a subclass of mp_table inside another mp_table object because of this bug: https://savannah.gnu.org/bugs/index.php?65037.

To work around these issues, your “table subclass” can inherit from this class. An object of this class isn’t a table or mp_table object, but rather it contains one and attempts to act like one. That is, it delegates method calls (currently only those available in mp_table, listed below) to the contained table object.

The class of the contained table object is either table or mp_table and is determined by mp_table_class().

Limitations

  1. The Octave bug mentioned above also affects tables that inherit from mp_table_subclass. That is, such tables can be nested inside tables of type table or mp_table, but not inside tables that are or inherit from mp_table_subclass.

  2. In MATLAB, when nesting an mp_table_subclass object within another mp_table_subclass object, one cannot use multi-level indexing directly. E.g. If T2 is a variable in T1 and x is a variable in T2, attempting x = T1.T2.x will result in an error. The indexing must be done in multiple steps T2 = T1.T2; x = T2.x. Note: This only applies to MATLAB, where the contained table is a table. It works just fine in Octave, where the contained table is an mp_table.

Important

Since the dot syntax T.<var_name> is used to access table variables, you must use a functional syntax <method>(T,...), as opposed to the object-oriented T.<method>(...), to call methods of this class or subclasses, as with mp_table.

mp.mp_table_subclass Properties:
  • tab - (table or mp_table) contained table object this class emulates

mp.cost_table Methods:
  • mp_table_subclass() - construct object

  • get_table() - return the table stored in tab

  • set_table() - assign a table to tab

  • istable() - true for mp_table objects

  • size() - dimensions of table

  • isempty() - true if table has no columns or no rows

  • end() - used to index last row or variable/column

  • subsref() - indexing a table to retrieve data

  • subsasgn() - indexing a table to assign data

  • horzcat() - concatenate tables horizontally

  • vertcat() - concatenate tables vertically

  • display() - display table contents

See also mp_table, mp_table_class().

Method Summary
get_table()
T = get_table(obj)
set_table(T)
set_table(obj, T)