How to use .m file when using Autodefine Input Types and mex file when running

조회 수: 1 (최근 30일)
Nathan Royer
Nathan Royer 2021년 12월 24일
답변: Pratyush 2024년 2월 15일
Is there a way in for my matlab code to understand that my script is being run via the "Autodefine Input Types" in the MATLAB Coder project gui? There is coder.target, but
coder.target('MATLAB')
returns true which also returns true when just running the script from the matlab command window.
What I want to have happen is:
if (running_normally)
mex_file('my_function', args);
elseif (generating_mex_file || running_Autodefine_Input_Types)
my_function(args);
end

답변 (1개)

Pratyush
Pratyush 2024년 2월 15일
Hi Nathan,
To differentiate between normal execution and various stages of code generation in MATLAB, including the "Autodefine Input Types" phase in MATLAB Coder GUI, you can use conditional checks with "coder.target". While there's no direct way to detect the "Autodefine Input Types" phase, you can use the following logic:
  • Use "coder.target('MEX')" to determine if the code is being generated for a MEX file.
  • Use "coder.target('codegen')" to check for any code generation process, which would cover the "Autodefine Input Types" phase.
  • Use an "else" statement for normal execution when not generating code.
This allows you to run different code paths depending on whether you are generating MEX files, running the "Autodefine Input Types" phase, or executing your script normally.

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by