cell2struct — Convert a cell array into a struct or struct array.
cell2struct(C, fields, dim) maps entries along dimension dim of C to named fields. Remaining dimensions become the struct-array shape.
Syntax
S = cell2struct(C, fields, dim)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
C | Any | Yes | — | Cell array containing field values. |
fields | Any | Yes | — | Field names as char, string, or cellstr. |
dim | IntegerScalar | Yes | — | Dimension whose entries correspond to field names. |
Returns
| Name | Type | Description |
|---|---|---|
S | Any | Struct or struct array result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:cell2struct:InvalidInput | Arguments are not a cell array, field-name list, and valid dimension. | cell2struct: invalid input |
RunMat:cell2struct:ShapeMismatch | The number of field names does not match the selected cell dimension. | cell2struct: field count does not match selected dimension |
How cell2struct works
fieldsmay be a string scalar, string array, character matrix, character vector, or cell array of text scalars.- The selected dimension must have the same extent as the number of field names.
- When the remaining dimensions contain a single element, the result is a scalar struct.
- Larger remaining dimensions are represented as a RunMat struct-array cell container.
Does RunMat run cell2struct on the GPU?
No GPU kernels are launched.
GPU memory and residency
The result is host-resident.
Example
Converting a row cell into a scalar struct
S = cell2struct({1, 'Ada'}, {'id','name'}, 2)Expected output:
S = struct with fields: id, nameUsing cell2struct with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how cell2struct changes the result.
Run a small cell2struct example, explain the result, then change one input and compare the output.
FAQ
Why are non-scalar struct arrays represented as cells?⌄
RunMat currently represents struct arrays as cell arrays containing struct values, matching existing table and struct-array runtime conventions.
Related Cells functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how cell2struct is executed, line by line, in Rust.
- View the source for cell2struct in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.