assignin — Assign an already evaluated value to a variable in the base or caller workspace.
assignin(workspace, name, value) transfers the already evaluated value to a whole variable in the selected base or caller workspace, creating that binding when necessary. It has no public output and performs no numeric conversion.
Syntax
assignin(workspace, name, value)Inputs
workspace- Type
StringScalar- Required
- Yes
- Description
- `base` or `caller` workspace selector.
name- Type
StringScalar- Required
- Yes
- Description
- Workspace variable name.
value- Type
Any- Required
- Yes
- Description
- Value to assign into the selected workspace.
Errors
RunMat:DynamicWorkspaceRequiresVm- When
- A dynamic workspace builtin is dispatched without an active workspace execution context.
- Message
dynamic workspace builtin requires an active workspace execution context
RunMat:assignin:TooManyOutputs- When
- One or more outputs are requested from assignin.
- Message
assignin: too many output arguments
RunMat:DynamicWorkspaceName- When
- The variable-name argument is not a valid MATLAB variable name.
- Message
assignin: invalid workspace variable name
Arguments and effects
The workspace selector is a character row or scalar string naming base or caller. At the command prompt they address the same workspace; inside a function, caller addresses the calling function's workspace.
The name is one valid variable identifier, not an indexed expression: it begins with an English letter, continues with English letters, digits, or underscores, is not a language keyword, and does not exceed namelengthmax characters.
The value expression is evaluated in the scope containing the assignin call before the resulting scalar or array value is transferred to the selected workspace. A request for any public output raises RunMat:assignin:TooManyOutputs.
Integer values retain exact class, shape, and authoritative storage; wide uint64 values are not routed through double.
GPU execution
Assignment is structural. A resident value retains its provider-owned representation; assignin itself launches no numeric kernel and does not gather or re-upload that payload.
Examples
Export an exact integer array to the base workspace
base = uint64(9007199254740992); assignin('base', 'counts', base + uint64([1 2])); selected = evalin('base', 'counts');Expected output:
selected retains uint64 values above flintmaxAssign in the calling workspace
outer_x = 5; result = helper();
function out = helper()
out = evalin('caller', 'outer_x + 2');
assignin('caller', 'caller_z', 11);
endExpected output:
result = 7; caller_z = 11Evaluate an expression before assigning its result
publish_result([1 2 3]); selected = evalin('base', 'published_result');
function publish_result(A)
result = sum(A);
assignin('base', 'published_result', result);
endExpected output:
selected = 6Using assignin with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how assignin changes the result.
Run a small assignin example, explain the result, then change one input and compare the output.
FAQ
Does assignin evaluate the value in the destination workspace?⌄
No. Its value expression is evaluated in the calling scope, then the resulting value is transferred.
Can the name contain indexing such as A(3)?⌄
No. assignin writes a whole workspace variable; evalin can evaluate destination-workspace indexed source when necessary.
Are integer arrays converted to double?⌄
No. Exact integer class, shape, and payload are preserved, including uint64 values beyond flintmax.
Does a resident GPU value move to the CPU?⌄
No. The selected workspace retains the provider-owned value without a gather performed by assignin.
What value does assignin return?⌄
It has no public output; requesting one is an error.
Related Introspection functions
addlistener · addParameter · addprop · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · feval · findprop · func2str · functions · get.p · getcallinfo · getmethod · inputname · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · isvalid · keyboard · loadobj · localfunctions · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mfilename · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · new_object · notify · numArgumentsFromSubscript · onCleanup · parse · saveobj · set.p · stats · str2func · subsasgn · subsref · superclasses · underlyingType · verLessThan · version · which · who · whos
Source you can read
Every RunMat function's source is public. Read exactly how assignin is executed, line by line, in Rust.
- View the source for assignin 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.