Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

MATLAB MEX interface to a class object with multiple functions

Date: 2022-09-20 15:59:28

I am using the MEX interface to run C++ code in MATLAB. I would like to add several functions to MATLAB for handling a System object: 

 

sysInit() sysRefresh() sysSetAttribute(name, value) String = sysGetAttribute(value) sysExit() 

Since each MEX dll can contain one function, I need to find a way to store the pointer to the global System object which will exist until deleted by a call to sysExit.

How can I do this in MATLAB properly? Are there any ways to store global pointers across calls to MEX functions? 

Answers: 

One common approach is to have several m-file functions that provide the public interface, e.g. sysInit.m, sysRefresh.m, etc.

Each of these m-files calls the mex function with some kind of handle, a string (or number) identifying the function to call, and any extra args. For example, sysRefresh.m might look like: 

   


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com