I have a custom C/C++ function which accepts a pointer as an input that I would like to include in my Simulink model. How can I implement this so that I can pass data by reference from Simulink?

 採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 1 月 25 日
編集済み: MathWorks Support Team 2025 年 2 月 7 日

1 投票

One option for passing data by reference is to create an S-Function block for the custom C/C++ code that accepts pointers. To integrate pre-existing code, you can use the Legacy Code Tool to generate an S-Function block. For more information, execute the following command in the MATLAB R2020b command window:
>> web(fullfile(docroot, 'simulink/sfg/integrating-existing-c-functions-into-simulink-models-with-the-legacy-code-tool.html'))
An alternative approach is to call your C++ function from a MATLAB Function Block using "coder.ceval". You can then pass your inputs by reference using "coder.ref", "coder.rref", or "coder.wref". For example, the call to a C++ function "sort" within the MATLAB Function Block might look like:
coder.ceval('sort', coder.ref(myArray), arrayLength);
For more information on calling C/C++ code from a MATLAB Function block and the different options for passing data by reference, you can access the documentation by executing the following command in the MATLAB R2020b command window:
>> web(fullfile(docroot, 'simulink/ug/incorporate-c-code-using-a-matlab-function-block.html'))
Please follow the link below to search for the required information regarding the current release:

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Simulink についてさらに検索

製品

リリース

R2020b

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by