Call Library Functions on macOS
In the previous step, you built a MATLAB® interface to the C++ matrixOperations
library in the
matrixlib
folder.
Set MATLAB Path
Add the MATLAB interface file to the MATLAB path.
addpath('matrixlib')
Copy Library File to Interface Folder
Put the shared library file in the folder with the MATLAB interface file.
copyfile(fullfile(productPath,"maci64","*.dylib"),"matrixlib","f")
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 interface filematrixlibInterface.dylib
and shared librarylibmwmatrixOperations.dylib
.Identify the package name (calling syntax) as
clib.matrixlib
.