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

2 次查看(过去 30 天)
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