mxGetProperty (C and Fortran)

Value of public property of MATLAB object

C Syntax

#include "matrix.h"
mxArray *mxGetProperty(const mxArray *pa, mwIndex index,
         const char *propname);

Fortran Syntax

mwPointer mxGetProperty(pa, index, propname)
mwPointer pa
mwIndex index
character*(*) propname



Pointer to an mxArray which is an object.


Index of the desired element of the object array.

In C, the first element of an mxArray has an index of 0. The index of the last element is N-1, where N is the number of elements in the array. In Fortran, the first element of an mxArray has an index of 1. The index of the last element is N, where N is the number of elements in the array.


Name of the property whose value you want to extract.


Pointer to the mxArray of the specified propname on success. Returns NULL in C (0 in Fortran) if unsuccessful. Common causes of failure include:

  • Specifying a nonexistent propname.

  • Specifying a nonpublic propname.

  • Specifying an index to an element outside the bounds of the mxArray. To test the index value, use mxGetNumberOfElements or mxGetM and mxGetN.

  • Insufficient heap space.


Call mxGetProperty to get the value held in the specified element. In pseudo-C terminology, mxGetProperty returns the value at:


mxGetProperty makes a copy of the value. If the property uses a large amount of memory, creating a copy might be a concern. There must be sufficient memory (in the heap) to hold the copy of the value.


Display Name Property of timeseries Object

Create a MEX file, dispproperty.c, in a folder on your MATLAB® path.

 * dispproperty.c - Display timeseries Name property
 * This is a MEX file for MATLAB.
 * Copyright 2013 The MathWorks, Inc.
 * All rights reserved.
#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, 
                 const mxArray *prhs[])
  /* Check for proper number of arguments. */
  if(nrhs!=1) {
    mexErrMsgIdAndTxt( "MATLAB:dispproperty:invalidNumInputs",
            "One input required.");
  } else if(nlhs>1) {
    mexErrMsgIdAndTxt( "MATLAB:dispproperty:maxlhs",
            "Too many output arguments.");
  /* Check for timeseries object. */
  if (!mxIsClass(prhs[0], "timeseries")) {
    mexErrMsgIdAndTxt( "MATLAB:dispproperty:invalidClass",
            "Input must be timeseries object.");
  plhs[0] = mxGetProperty(prhs[0],0,"Name");  

Build the MEX file.


Create a timeseries object.

ts = timeseries(rand(5, 4),'Name','LaunchData');

Display name.

tsname = dispproperty(ts)
tsname =

Change Object Color

Open and build the mexgetproperty.c MEX file in the matlabroot/extern/examples/mex folder.

Introduced in R2008a

Was this topic helpful?