| MATLAB Application Program Interface | Search  Help Desk |
| mexGet | Examples See Also |
Get the value of the specified Handle Graphics property
#include "mex.h" const mxArray *mexGet(double handle, const char *property);handle
NULL on failure. The return argument from mexGet is declared as constant, meaning that it is read only and should not be modified. Changing the data in these mxArrays may produce undesired side effects.
Call mexGet to get the value of the property of a certain graphics object. mexGet is the API equivalent of MATLAB's get function. To set a graphics property value, call mexSet.
Consider a MEX-file that expects a graphics handle as its first input argument. The MEX-file asks for the Color property associated with the handle, and then modifies this color:
#define red 0
#define green 1
#define blue 2
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[])
{
double handle;
const mxArray *color_array_ptr;
mxArray *new_color_array_ptr;
double *color, *new_color;
/* Assume that the first input argument is a graphics
handle. */
if(nrhs != 1 || !mxIsDouble(prhs[0]))
mexErrMsgTxt("Must be called with a valid handle");
handle = mxGetScalar(prhs[0]);
/* Get the "Color" property associated with this handle. */
color_array_ptr = mexGet(handle, "Color");
if (color_array_ptr == NULL)
mexErrMsgTxt("Could not get this handle property");
/* The returned "Color" property is a 1-by-3 matrix of
primary colors. */
color = mxGetPr(color_array_ptr);
/* Create a new mxArray for color */
new_color_array_ptr = mxCreateDoubleMatrix(1, 3, mxREAL);
new_color = mxGetPr(plhs[0];
new_color[red] = (1 + color[red]) /2;
new_color[green] = color[green]/2;
new_color[blue] = color[blue]/2;
/* Reset the "Color" property to use the new color. */
if(mexSet(handle, "Color", new_color_array_ptr))
mexErrMsgTxt("Could not set a new 'Color' property.");
}
For an additional example, see mexget.c in the mex subdirectory of the examples directory.
mexSet