This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

engPutVariable (C and Fortran)

Put variable into MATLAB engine workspace

C Syntax

#include "engine.h"
int engPutVariable(Engine *ep, const char *name, const mxArray 

Fortran Syntax

integer*4 engPutVariable(ep, name, pm)
mwPointer ep, pm
character*(*) name



Engine pointer


Name of mxArray in the engine workspace


mxArray pointer


0 if successful and 1 if an error occurs.


engPutVariable writes mxArray pm to the engine ep, giving it the variable name name.

If the mxArray does not exist in the workspace, the function creates it. If an mxArray with the same name exists in the workspace, the function replaces the existing mxArray with the new mxArray.

The limit for the size of data transferred is 2 GB.

Do not use MATLAB® function names for variable names. Common variable names that conflict with function names include i, j, mode, char, size, or path. To determine whether a particular name is associated with a MATLAB function, use the which function.

The engine application owns the original mxArray and is responsible for freeing its memory. Although the engPutVariable function sends a copy of the mxArray to the MATLAB workspace, the engine application does not need to account for or free memory for the copy.


See the following examples in matlabroot/extern/examples/eng_mat.

  • engdemo.c for a C example on UNIX® operating systems.

  • engwindemo.c for a C example on Microsoft® Windows® operating systems.

Was this topic helpful?