table2struct — Convert a table into row structs or a scalar struct of variables.
table2struct(T) converts each table row into a struct with fields matching table variable names. table2struct(T, "ToScalar", true) returns one scalar struct whose fields contain whole table variables.
Syntax
S = table2struct(T)
S = table2struct(T, 'ToScalar', tf)Inputs
T- Type
Any- Required
- Yes
- Description
- Input table or timetable.
ToScalar- Type
StringScalar- Required
- Yes
- Description
- Name of the scalar-structure option.
tf- Type
PropertyValue- Required
- Yes
- Description
- Logical selector for a scalar structure of complete variables.
Returns
B- Type
Any- Description
- Converted output value.
Errors
RunMat:table:InvalidArgument- When
- Arguments or table metadata are invalid.
- Message
table: invalid argument
RunMat:table:InvalidIndex- When
- Table indexing is invalid.
- Message
table: invalid index
RunMat:table:InvalidVariable- When
- A table variable name or value is invalid.
- Message
table: invalid variable
Behavior
Variable order is preserved.
The default conversion returns one row struct per table row; integer fields retain their exact scalar class and value.
"ToScalar" keeps every complete table variable in one scalar struct without converting integer storage.
The documented logical ToScalar selector works in MATLAB-compatible mode. Typed-integer selector values are available only when RunMat extensions are enabled.
Execution and placement
Table and struct containers are host values.
Host-side conversion is a fusion boundary.
Examples
Convert rows to structs
T = array2table([1 3;2 4],'VariableNames',{'A','B'}); S = table2struct(T)Convert variables to one scalar struct
T = array2table([1 3;2 4],'VariableNames',{'A','B'}); S = table2struct(T,'ToScalar',true)Using table2struct with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how table2struct changes the result.
Run a small table2struct example, explain the result, then change one input and compare the output.
Related Table functions
Table
array2table · array2timetable · categorical · cell2table · dictionary · groupsummary · head · iscategorical · isordinal · istable · istimetable · ordinal · pivot · rowfilter · struct2table · table · table2array · table2cell · table2timetable · timerange · timetable · timetable2table · uitable · vartype
Indexing
dictionary.subsasgn · dictionary.subsref · table.subsasgn · table.subsref
Source you can read
Every RunMat function's source is public. Read exactly how table2struct is executed, line by line, in Rust.
- View the source for table2struct in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.