MATLAB Answers

Converting Matlab code with a function handle within a structure to C/C++

16 ビュー (過去 30 日間)
mcor 2019 年 5 月 10 日
コメント済み: mcor 2019 年 5 月 11 日
I'm trying to use the MATLAB Coder app to convert a series of functions to C/C++ functions.
I create a structure, and some elements of that structure are functions, like in the image below (the image represents a silly example with no meaning).
However, the converter fails because of the function handle:
"Function output 'model' cannot be a structure containing a function handle".
Anyone knows if I'm doing something wrong or there's a workaround it? I do need functions within a structure.
Machine: Mac,
Version: Matlab 2017b
Any help is appreciated.

  0 件のコメント



Ryan Livingston
Ryan Livingston 2019 年 5 月 11 日
Function handles, and values containing them, are not supported as inputs and outputs from entry-point functions. As a workaround could move testFun to a separate file on the path, return the name, and use str2func when back in MATLAB.
If you describe what you're trying to achieve with this struct, there may be a better workaround.

  1 件のコメント

mcor 2019 年 5 月 11 日
Thank you Ryan for the fast answer.
What i'm trying to do is to build a structure (model) with the several function handles I need in the main code, and pass "model" to all functions that need the function handles.
I made it this way to avoid having many many files, one for each function handle.
but I think your workaround may work.


その他の回答 (0 件)


Community Treasure Hunt

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

Start Hunting!

Translated by