Main Content

Call matrixoperations Library Functions

In the previous step, you built a MATLAB® interface to the C++ matrixOperations library.

Building interface file 'matrixOperationsInterface.dll' for clib package 'matrixOperations'.
Interface file 'matrixOperationsInterface.dll' built in folder 'C:\Users\Documents\MATLAB\matrixOperations'.

To use the library, add the interface file folder to the MATLAB path.
addpath('C:\Users\Documents\MATLAB\matrixOperations')

Set MATLAB Path

addpath('matrixOperations')

View Help

At the MATLAB command prompt, type these commands to open documentation for the library in your help browser.

doc clib.matrixOperations.Mat  %load the package
doc clib.matrixOperations      %display package members

To display signatures for the package functions, click the links for addMat, updateMatByX, and updateMatBySize.

To display information about class clib.matrixOperations.Mat, click the link for Mat.

Call Library Functions

To create a Mat object and call functions in the library, type:

matObj = clib.matrixOperations.Mat;   % Create a Mat object
intArr = [1,2,3,4,5];
matObj.setMat(intArr);     % Set the values to intArr
retMat = matObj.getMat(5)  % Display the values
retMat = 1×5 int32 row vector    
   1   2   3   4   5

Share Interface

To give the interface to another MATLAB user, create a toolbox installation (.mltbx) file. Using the instructions in Distribute MATLAB Interface to C++ Library:

  • Set the toolbox folder to your matrixOperations folder which contains interface file matrixOperationsInterface.dll and shared library matrixOperations.dll.

  • Identify the package name (calling syntax) as clib.matrixOperations.