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

NameTypeRequiredDefaultDescription
CAnyYesCell array containing field values.
fieldsAnyYesField names as char, string, or cellstr.
dimIntegerScalarYesDimension whose entries correspond to field names.

Returns

NameTypeDescription
SAnyStruct or struct array result.

Errors

IdentifierWhenMessage
RunMat:cell2struct:InvalidInputArguments are not a cell array, field-name list, and valid dimension.cell2struct: invalid input
RunMat:cell2struct:ShapeMismatchThe number of field names does not match the selected cell dimension.cell2struct: field count does not match selected dimension

How cell2struct works

  • fields may 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, name

Using 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.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how cell2struct is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.