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!! :)
0 个评论
回答(2 个)
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!