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

조회 수: 4 (최근 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 CenterFile Exchange에서 Interactive Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by