Preliminary documentation for Ice 3.7.1 Beta. Do not use in production applications. Refer to the space directory for other releases.

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:

Slice
struct Employee
{
    long number;
    string firstName;
    string lastName;
}

The MATLAB mapping generates the following definition for this structure:

MATLAB
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 TypeDefault Value
stringEmpty string
enumFirst enumerator in enumeration
structDefault-constructed value
NumericZero
boolfalse
sequenceEmpty array
dictionaryInstance of the mapped type
classEmpty array

You can also declare different default values for members of primitive and enumerated types.

See Also

  • No labels