assignin — Assign an already evaluated value to a variable in the base or caller workspace.
assignin(ws, var, val) assigns the already evaluated value val to the variable named by var in the base or caller workspace. The function creates the variable when necessary and has no public output.
Syntax
assignin(workspace, name, value)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
workspace | StringScalar | Yes | — | `base` or `caller` workspace selector. |
name | StringScalar | Yes | — | Workspace variable name. |
value | Any | Yes | — | Value to assign into the selected workspace. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:DynamicWorkspaceRequiresVm | A dynamic workspace builtin is dispatched outside the VM workspace frame. | dynamic workspace builtin requires VM workspace context |
RunMat:assignin:TooManyOutputs | One or more outputs are requested from assignin. | assignin: too many output arguments |
RunMat:DynamicWorkspaceName | The variable-name argument is not a valid MATLAB variable name. | assignin: invalid workspace variable name |
How assignin works
wsis a character vector or string scalar selecting thebaseorcallerworkspace. At the command prompt those workspaces are equivalent; inside a function,callerselects the workspace of the calling function.varis a character vector or string scalar containing one valid variable name, not an indexed expression. A valid name starts with an English letter, continues with English letters, digits, or underscores, is not a language keyword, and contains at mostnamelengthmaxcharacters.valcan have any data type and can be scalar or array valued. Expressions are evaluated in the function containing the call before the resulting value is assigned.- Integer values retain their exact class, shape, and authoritative storage. Wide
uint64values are not converted through double. - Assignment is structural: resident values retain provider ownership without gather, re-upload, or numeric computation.
- The public function has no output. Requesting an output raises
RunMat:assignin:TooManyOutputs.
Does RunMat run assignin on the GPU?
assignin performs no numerical operation. A GpuTensor is cloned into the selected workspace as the same provider-owned value, so class, shape, exact integer payload, and residency remain unchanged and no kernel or host transfer occurs.
Examples
Export an exact integer array to the base workspace
function publishCounts(counts)
assignin("base", "counts", uint64(counts))
endChange a variable in the calling function
function outer
age = 37;
updateCaller;
disp(age)
end
function updateCaller
assignin("caller", "age", 42)
endAssign an evaluated expression rather than source text
function publishResult(A)
result = sum(A, "native");
assignin("base", "result", result)
endUsing 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 val in the destination workspace?⌄
No. The expression producing val is evaluated in the function containing the assignin call, and the resulting value is then transferred to the selected workspace.
Can var contain indexing such as A(3)?⌄
No. assignin assigns a whole workspace variable. Use evalin when destination-workspace indexed assignment is unavoidable.
Are integer arrays converted to double?⌄
No. Assignment preserves exact integer class, shape, and values, including uint64 values above flintmax.
Does a GPU value move to the CPU?⌄
No. RunMat transfers the value object structurally and retains its provider-owned resident representation.
What value does assignin return?⌄
It has no public output. Assigning its call result is an error.
Related Introspection functions
addprop · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · evalc · feval · findprop · getcallinfo · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · keyboard · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mislocked · mlock · munlock · namelengthmax · narginchk · nargoutchk · notify · onCleanup · stats · str2func · superclasses · underlyingType · verLessThan · version · which · who · whos
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. 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 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.