Documentation Center

  • Trial Software
  • Product Updates

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. Use mxGetNumberOfElements or mxGetM and mxGetN to test the index value.

  • 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. This might be a concern if the property uses a large amount of memory. There must be sufficient memory (in the heap) to hold the copy of the value.


Display Property

This example displays the Name property of a timeseries object.

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

 * mxgetproperty.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:mxgetproperty:invalidNumInputs",
            "One input required.");
  } else if(nlhs>1) {
    mexErrMsgIdAndTxt( "MATLAB:mxgetproperty:maxlhs",
            "Too many output arguments.");
  /* Check for timeseries object. */
  if (!mxIsClass(prhs[0], "timeseries")) {
    mexErrMsgIdAndTxt( "MATLAB:mxgetproperty:invalidClass",
            "Input must be timeseries object.");
  plhs[0] = mxGetProperty(prhs[0],0,"Name");  

Build the MEX-file.


Create a timeseries object.

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

Display name.

tsname = mxgetproperty(tsobj)
tsname =
Was this topic helpful?