MATLAB Mapping for Structures
On this page:
Basic MATLAB Mapping for Structures
A Slice structure maps to a MATLAB value class containing a public property for each member of the structure. For example, here is our Employee
structure once more:
struct Employee { long number; string firstName; string lastName; }
The MATLAB mapping generates the following definition for this structure:
classdef Employee properties number int64 firstName char lastName char end methods function obj = Employee(number, firstName, lastName) ... end end ... end
The class provides a constructor whose optional arguments correspond to the data members. This allows you to instantiate and initialize the class in a single statement (instead of having to first instantiate the class and then assign to its members). You must either call the constructor with no arguments or with arguments for all of the data members.
Default Property Values
Calling the generated constructor with no arguments assigns a default value appropriate for each member's type:
Data Member Type | Default Value |
---|---|
string | Empty string |
enum | First enumerator in enumeration |
struct | Default-constructed value |
Numeric | Zero |
bool | false |
sequence | Empty array |
dictionary | Instance of the mapped type |
class | Empty array |
You can also declare different default values for members of primitive and enumerated types.