Embedded MATLAB function: Call global struct; Error: Referencing a component from array of non-scalar values is not supported for code generation.

5 ビュー (過去 30 日間)
Hello Everybody!
I'm trying to use a global struct variable defined via a Simulink.Bus + Simulink.Signal + MATLAB Value Initialisation struct (all fields = 0) in a Simulink Modell. I've successfully implemented the global struct variable, however as soon as I try to work with it in a Simulink-embedded MATLAB function I get the following Coder Error for every single code line where I want to access any field of my global struct:
"Referencing a component from array of non-scalar values is not supported for code generation."
My struct has the following field architecture:
Init_FMS.FM.Fly_BM = false;
Init_FMS.FM.Fly_FPL = false;
Init_FMS.FM.Fly_Manual = false;
Init_FMS.BM.Psi = single(0);
Init_FMS.BM.H = single(0);
Init_FMS.BM.H_dot = single(0);
Init_FMS.BM.IAS = single(0);
Init_FMS.FPL.GEN.Name = uint8(zeros(1,20));
Init_FMS.FPL.GEN.Num_of_WPTs = uint16(0);
Init_FMS.FPL.WPT.ID = uint16(zeros(maxNumWPTs,1));
Init_FMS.FPL.WPT.LAT = double(zeros(maxNumWPTs,1));
Init_FMS.FPL.WPT.LON = double(zeros(maxNumWPTs,1));
Init_FMS.FPL.WPT.ALT = single(zeros(maxNumWPTs,1));
Init_FMS.FPL.WPT.VEL = single(zeros(maxNumWPTs,1));
Init_FMS.FPL.WPT.TRT = uint8(zeros( maxNumWPTs,1));
Init_FMS.FPL.WPT.Loiter_ID = uint16(zeros(maxNumWPTs,1));
Init_FMS.FPL.WPT.Loiter_Time = int16(zeros( maxNumWPTs,1));
Within the embedded function I call it just like a normal global variable before trying to write new data to the different fields:
function = Receive_FMS_ProcessInternData (...)
global FMS
if ...
if ...
FMS.FM.Fly_BM = true;
...
end
and so on.
What am I doing wrong (code/ variable settings?) to avoid getting the coder error all the time?
Thank you!! :)

回答 (2 件)

Suhan
Suhan 2017 年 5 月 23 日
Hi,
The error "Referencing a component from array of non-scalar values is not supported for code generation" typically comes up with Structure Arrays when dot notation is used to access the elements. Structures are supported for code generation, so that should not be an issue: http://www.mathworks.com/help/simulink/ug/matlab-language-features-supported-for-code-generation.html. Also, see if specifying the data type of the bus structure of the inputs and outputs to the MATLAB function block in the Model Explorer fixes the issue
  1 件のコメント
Franck Yin
Franck Yin 2017 年 5 月 29 日
編集済み: Franck Yin 2017 年 5 月 29 日
What worked for me : I forgot that my element was an array. After adding the index -"element(1).subelement" instead of "element.subelement" in my case- the problem was gone.

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


Andreas Kustermann
Andreas Kustermann 2017 年 5 月 24 日
Solved the problem, thank you. In the model explorer, for the respective settings of the Simulink.Signal its dimensions need to be set to "1" and "auto"; during my first setup I had specified the exact dimension size (= row number) of my global struct which was apparently wrong.

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by