Create a mex file of functions which are using in matlab app designer

조회 수: 7 (최근 30일)
Saravanan
Saravanan 2025년 3월 22일
편집: dpb 2025년 3월 24일
Having a function(Sample.m) which is called in pushbuttoncalllback changed value ,so i need to convert that function into mex file , that function contains data extraction function calls and plotting .
Using matlab coder , my entry point function is Sample.m , and in define input types , i am loading my mlapp file which is converted to .m file , so while loading this i am getting error class MAR_140_CAN_exported is not supported by coder. Types as it is a handle class?

답변 (1개)

dpb
dpb 2025년 3월 22일
이동: dpb 2025년 3월 22일
MATLAB Coder builds C/C++ code that is either turned into a standalone application of its own or used to build libraries or classes that can be called from other C/C++ applications. It does NOT build MATLAB .mex functions to be called from MATLAB; that is done with mex. MEX files are written in C/C++/Fortran/... but require a "glue" interface routine to pass arguments to the function and return outputs to MATLAB.
You would have to write that interface routine and have it call the output C code from the app. Unless it has been demonstrated that the m-file code runs too slowly, it would be far simpler for development and ongoing code maintenance to leave the code in MATLAB; when the app is packaged it won't be accessible to end users anyway if that is the concern.
The statement that the function contains both data extraction and plotting also makes one wonder if it would be wise to further modularize the code into separate functions--those that deal strictly with the data acquisition/processing and then call the plotting routines.
We would need more information on the actual content of this function and why you think it needs to be turned into a mex file to comment specifically, but my strong recommendation would be to first ensure it has been optimized in MATLAB syntax/performance and then, only if it has unacceptable performance issues, consider mex.
  댓글 수: 2
Saravanan
Saravanan 2025년 3월 24일
Could please share optimization techniques to reduce execution time and increase tool performance in MATLAB app designer
dpb
dpb 2025년 3월 24일
편집: dpb 2025년 3월 24일
See <Techniques to Improve Performance> for general tips; specifics would depend on the implementation of the code itself. First and foremost, however, is to profile the code to find where the bottleneck(s) actually is(are).
"We would need more information on the actual content of this function ... to comment specifically..."
Note that first-time loading of an app is always slow and mex won't fix that...but, the one specific recommendation I made earlier may help at least a little.-- from the link above."Use modular programming. To avoid large files and files with infrequently accessed code, split your code into simple and cohesive functions. This practice can decrease first-time run costs."
If your statement above is accurate that everything is in one function, it's almost certain it should be refactored.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by