How to batch convert to C/C++ using Coder App?

1 回表示 (過去 30 日間)
shawn gong
shawn gong 2020 年 10 月 20 日
編集済み: Shaunak 2025 年 6 月 9 日
Hi,
I have a large Matlab package that consists of hundreds of m files. They are in several folders, some start with '+'.
How do I batch convert them to C/C++ using Coder App? Do I have to run Coder App one-by-one?
Thanks.

回答 (1 件)

Shaunak
Shaunak 2025 年 6 月 9 日
編集済み: Shaunak 2025 年 6 月 9 日
Hi Shawn,
It is my understanding that you want to batch convert a large MATLAB package consisting of many M files into C/C++ code using the MATLAB Coder App.
Although the MATLAB Coder App does not support batch processing of multiple files directly in one go, however, you can automate the process using a script that calls the “codegen” function for each entry-point function.
Here’s how you can do it:
  • Organize Your Code: Ensure that your MATLAB code is structured properly, with entry-point functions accessible for code generation.
  • Create a Script for Batch Processing: You can write a MATLAB script to loop through your entry-point functions and generate the C/C++ code. Here’s an example:
% List of entry-point functions
entryPoints = {'function1', 'function2', 'function3'}; % Add your function names here
% Loop through each entry-point function
for i = 1:length(entryPoints)
% Generate C/C++ code for each function
codegen(entryPoints{i}, '-args', {zeros(1, 10), zeros(1, 10)}); % Adjust input arguments as needed
End
For any queries on “codegenfuction, kindly refer to the MathWorks documentation linked below:
  • Run the Script: Execute the script in MATLAB, and it will generate the C/C++ code for each specified function.
  • Using the Coder App: If you prefer using the MATLAB Coder App, you will need to manually select each function and specify input types, which can be time-consuming for many files.
By using the approach mentioned above, you can efficiently generate C/C++ code for multiple functions without having to run the Coder App for each function separately.
Hope this helps!

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by