Convert MATLAB structure to C-style structure for use with shared library
Call the addStructFields function by creating a variable of type c_struct.
Load the shrlibsample library, which contains the c_struct type.
if ~libisloaded('shrlibsample') addpath(fullfile(matlabroot,'extern','examples','shrlib')) loadlibrary('shrlibsample') end
Display function signatures for shrlibsample and search the list for the addStructFields entry.
The input argument is a pointer to a c_struct data type.
Create a MATLAB structure, sm.
sm.p1 = 476; sm.p2 = -299; sm.p3 = 1000;
Construct a libstruct object sc from the c_struct type.
sc = libstruct('c_struct',sm)
The fields of sc contain the values of the MATLAB structure, sm.
Call the addStructFields function.
ans = 1177
To clean up, first clear the libstruct object, and then unload the library.
clear sc unloadlibrary shrlibsample
Use with libraries that are loaded using the loadlibrary function.
You can only use the libstruct function on scalar structures.
When converting a MATLAB structure to a libstruct object, the structure must adhere to the requirements listed in Structure Argument Requirements.
If a function in the shared library has a structure argument, use libstruct to create the argument. The libstruct function creates a C-style structure that you pass to functions in the library. You handle this structure in MATLAB as you would a true MATLAB structure.