There are two mappings for Slice structures, depending on whether they contain class data members:
- A structure that does not contain class data members maps to a MATLAB value type
- A structure that contains class data members maps to a MATLAB handle type
The mappings are nearly identical, but you need to be aware of the differences because they behave differently at run time in some situations.
On this page:
Table of Contents | ||
---|---|---|
|
...
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:
...
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.
Ztop |
---|
Handle Mapping for Structures
Suppose we modify the Employee
structure to add a class data member:
Code Block | ||||
---|---|---|---|---|
| ||||
class Photo
{
...
}
struct Employee
{
long number;
string firstName;
string lastName;
Photo avatar;
}
|
The MATLAB mapping generates a handle class for this structure:
Code Block | ||
---|---|---|
| ||
classdef Employee < matlab.mixin.Copyable
properties
number int64
firstName char
lastName char
avatar
end
methods
function obj = Employee(number, firstName, lastName, avatar)
...
end
...
end
end |
The class derives from matlab.mixin.Copyable
, which derives from handle
. The constructor accepts optional arguments corresponding to the data members, allowing 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.
Ztop |
---|
Comparing Value and Handle Semantics
A structure that contains one or more class data members must be mapped as a handle class to support the Ice run time's unmarshaling requirements. As you may already know, MATLAB treats value types differently than handle types when passing them as parameters: value types are passed by value (i.e., copied) while handle types are passed by reference. Please keep this difference in mind while developing your application.Regardless of whether a structure is mapped as a value type or a handle type, instances can be compared using the isequal
function and copied using the copy
function.
Ztop |
---|
Default Property Values
...