Main Content

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

#include "fintrf.h"
mwPointer mxGetProperty(pa, index, propname)
mwPointer pa
mwIndex index
character*(*) propname

Arguments

pa

Pointer to an mxArray which is an object.

index

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.

propname

Name of the property whose value you want to extract.

Returns

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.

Description

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

pa[index].propname

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

Examples

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.

mex('-v','dispproperty.c')

Create a timeseries object.

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

Display name.

tsname = dispproperty(ts)
tsname =
LaunchData

Change Object Color

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

Limitations

  • mxGetProperty is not supported for standalone applications, such as applications built with the MATLAB engine API.

  • Properties of type datetime are not supported.

Version History

Introduced in R2008a