Generate Code for unused Variables in Data Dictionary
이전 댓글 표시
is it possible to declare some variables as global inside a datadictionary and have these variables show up in a declaration file even if they are unused in the model?
채택된 답변
추가 답변 (2개)
Mark McBroom
2024년 11월 30일
이동: Walter Roberson
2024년 11월 30일
0 개 추천
AFAIK this is not possible. One simple workaround would be to create global data stores in the model for each of these variables.
Sivsankar
2025년 1월 24일
You might consider creating a MATLAB struct with all the parameters and adding that struct to the SLDD file. This approach ensures that even if only one of the variables is used by the model, all the variable values will be exported to the generated code. You can refer to the following MATLAB answer for a similar query:
Here is a sample snippet illustrating how you can implement this workaround:
%create MATLAB struct
myParams = struct(...
'param1',4,...
'param2',5,...
'param3',6);
%create bus object for the struct
Simulink.Bus.createObject(myParams)
myParamsType = slBus1;
%create Simulink parameter of the struct
myParams = Simulink.Parameter(myParams);
myParams.DataType = 'Bus: myParamsType';
%add the Simulink parameter created to the sldd file
myDictionaryObj = Simulink.data.dictionary.open('filename.sldd');
dDataSectObj = getSection(myDictionaryObj,'Design Data');
addEntry(dDataSectObj,'Params',myParams)
Now, whenever you reference at least one parameter from this MATLAB struct, the generated code will include all the variables from this struct.
Thanks.
카테고리
도움말 센터 및 File Exchange에서 Simulink Coder에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!