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
) ormp_table
).In MATLAB,
table
is a sealed class, so you cannot inherit from it. You can, however, use a subclass ofmp_table
, but that can result in the next issue under Octave.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 ofmp_table
inside anothermp_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
ormp_table
object, but rather it contains one and attempts to act like one. That is, it delegates method calls (currently only those available inmp_table
, listed below) to the contained table object.The class of the contained table object is either
table
ormp_table
and is determined bymp_table_class()
.Limitations
The Octave bug mentioned above also affects tables that inherit from
mp_table_subclass
. That is, such tables can be nested inside tables of typetable
ormp_table
, but not inside tables that are or inherit frommp_table_subclass
.In MATLAB, when nesting an
mp_table_subclass
object within anothermp_table_subclass
object, one cannot use multi-level indexing directly. E.g. IfT2
is a variable inT1
andx
is a variable inT2
, attemptingx = T1.T2.x
will result in an error. The indexing must be done in multiple stepsT2 = T1.T2; x = T2.x
. Note: This only applies to MATLAB, where the contained table is atable
. It works just fine in Octave, where the contained table is anmp_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-orientedT.<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 objectget_table()
- return the table stored intab
set_table()
- assign a table totab
istable()
- true formp_table
objectssize()
- dimensions of tableisempty()
- true if table has no columns or no rowsend()
- used to index last row or variable/columnsubsref()
- indexing a table to retrieve datasubsasgn()
- indexing a table to assign datahorzcat()
- concatenate tables horizontallyvertcat()
- concatenate tables verticallydisplay()
- display table contents
See also
mp_table
,mp_table_class()
.