What are the limitation on arrays of objects with MATLAB coder?

1 回表示 (過去 30 日間)
Byron Caudle
Byron Caudle 2017 年 12 月 4 日
編集済み: Walter Roberson 2020 年 3 月 17 日
I read on the support page https://www.mathworks.com/help/simulink/ug/how-working-with-matlab-classes-is-different-for-code-generation.html that Arrays of Objects are not supported. Do this mean that I can't have a class with a property that is an array of objects (of another class)? Or does is mean that I can't have arrays of objects at all (not even in my main function)? I am thinking there must be some limited arrays of objects support, otherwise code generation from OO code would be pretty useless.
How does this limitation work with the Java coder?

回答 (1 件)

Denis Gurchenkov
Denis Gurchenkov 2018 年 2 月 22 日
The later is correct. As of R2017b, MATLAB Coder does not support arrays of objects, so if your MATLAB code creates an array of objects, such as
x = [MyClass(1), MyClass(2)];
or
x = repmat(MyClass(1), [3 4]);
then code generation will fail with an error message (presuming that there is a class MyClass in your code).
The only workaround as of now is to use cell arrays of objects, that is,
x = {MyClass(1), MyClass(2)};
should compile fine.
  1 件のコメント
Tom Shlomo
Tom Shlomo 2020 年 3 月 17 日
Has something changed in recent releases?

サインインしてコメントする。

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by