Main Content

Call Library Functions on Linux

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


Add the MATLAB interface file to the MATLAB path.


Copy Library File to Interface Folder

Put the compiled library file in the folder with the MATLAB interface file.


View Help

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

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

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

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

Call Library Functions

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

matObj = clib.matrixlib.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 matrixlib folder which contains the interface file

  • Put the compiled library file in the same folder.

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