---
title: "Structures"
url: https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures
language: matlab
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Structures

Programming language: MATLAB. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/csharp.md), [Java](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/java.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/js.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/php.md), [Python](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/swift.md).

## Struct Syntax

A structure groups one or more named fields, of any type, into a new type. For example:

```slice
module M
{
    struct TimeOfDay
    {
        short hour;         // 0 - 23
        short minute;       // 0 - 59
        short second;       // 0 - 59
    }
}
```

This definition introduces a new type named `TimeOfDay`. The name of a field must be unique within its structure.

A structure contains only fields: as elsewhere in Slice, type definitions cannot be nested, except for [modules](https://docs.zeroc.com/ice/3.8/slice/modules/matlab.md). Like every other type, you define a structure in a module.

## Language Mapping

A Slice structure maps to a MATLAB value class containing a public property for each field of the structure. For example, here is our Employee structure once more:

```slice
struct Employee
{
    ["matlab:identifier:Number"]
    long number;

    ["matlab:identifier:FirstName"]
    string firstName;

    ["matlab:identifier:LastName"]
    string lastName;
}
```

The MATLAB mapping generates the following definition for this structure:

```matlab
classdef Employee
    properties
        Number    (1, 1) int64
        FirstName (1, :) char
        LastName  (1, :) char
    end
    methods
        function obj = Employee(Number, FirstName, LastName)
            % ...
        end
    end
    % ...
end
```

### Generated Constructor

The generated constructor has one parameter for each property. You must either call this constructor with no arguments or with arguments for all the properties.

If you call the generated constructor with no argument, the constructor assigns default values to all properties (see [Fields](https://docs.zeroc.com/ice/3.8/slice/fields/matlab.md)).

## See Also

- [Fields](https://docs.zeroc.com/ice/3.8/slice/fields/matlab.md)
- [Classes](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/matlab.md)
