MATLAB Coder does not recognize dot notation in struct member assignment

2 ビュー (過去 30 日間)
Aaron Rice
Aaron Rice 2022 年 8 月 9 日
回答済み: Konstantinos Athanasiou 2022 年 8 月 11 日
% Unable to generate C Code using MATLAB Coder for simplified example function shown below. Error description states, "This assignment
% writes a 'double' value into a 'struct' type. Code generation does not support changing types through assignment. Check preceding
% assignment or input type specifications for type mismatches ".
function ExampleFunction() %#codegen
global SD
SD.a = 0.0;
SD.b = 1.0;
SD.a = SD.b;
end
  1 件のコメント
Konstantinos Athanasiou
Konstantinos Athanasiou 2022 年 8 月 11 日
Hi Aaron. Could you provide the codegen command you are using for the above example?

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

回答 (2 件)

Benjamin Thompson
Benjamin Thompson 2022 年 8 月 11 日
See the article "Name the C Structure Type to Use With a Global Structure Variable" in the MATLAB help documentation. You need to register the struct type with coder and map struct variables to registered types.

Konstantinos Athanasiou
Konstantinos Athanasiou 2022 年 8 月 11 日
The following codegen command compiles without errors for the provided example.
% codegen t -globals {'SD', struct('a', double(0), 'b', double(0))}
function r = t
global SD;
SD.a = 0.1;
SD.b = 0.2;
SD.a = SD.b;
r = SD.a;
end

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by