Embedded MATLAB function: Call global struct; Error: Referencing a component from array of non-scalar values is not supported for code generation.
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!! :)
0 Kommentare
Antworten (2)
Suhan
am 23 Mai 2017
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 Kommentar
Franck Yin
am 29 Mai 2017
Bearbeitet: Franck Yin
am 29 Mai 2017
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.
Siehe auch
Kategorien
Mehr zu Simulink Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!