This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

mexPutVariable (C)

Array from MEX function into specified workspace

C Syntax

#include "mex.h"
int mexPutVariable(const char *workspace, const char *varname, 
  const mxArray *pm);

Description

Note

To write MEX functions using modern C++ features and the MATLAB Data API, see C++ MEX Applications.

Call mexPutVariable to copy the mxArray, at pointer pm, from your MEX function into the specified workspace. MATLAB® assigns varname to the mxArray copied in the workspace. The function returns 0 on success; 1 on failure. A possible cause of failure is that pm is NULL.

mexPutVariable makes the array accessible to other entities, such as MATLAB, user-defined functions, or other MEX functions.

If a variable of the same name exists in the specified workspace, mexPutVariable overwrites the previous contents of the variable with the contents of the new mxArray. For example, suppose the MATLAB workspace defines variable Peaches as:

Peaches
1     2     3     4

and you call mexPutVariable to copy Peaches into the same workspace:

mexPutVariable("base", "Peaches", pm)

The value passed by mexPutVariable replaces the old value of Peaches.

Input Arguments

expand all

Scope of the array to copy, specified as const char*. The possible values are:

base

Copy mxArray to the base workspace.

caller

Copy mxArray to the caller workspace.

global

Copy mxArray to the list of global variables.

Name of mxArray in the workspace, specified as const char*.

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.

Pointer to the mxArray.

Examples

See these examples in matlabroot/extern/examples/mex:

Introduced before R2006a