How to initialize a Unit Delay block with a Bus signal from a Data Dictionary in the Model Workspace in R2021a?

조회 수: 20 (최근 30일)
My model contains a Bus signal feeding a Unit Delay block which should be initialized:
So that Bus elements a and b have different initial conditions.
I saw that one can use the following workflows:
But how can I create the MATLAB struct inside the Model Workspace which should get Bus type data from a Data Dictionary (DD). Besides this I also want to use variables/values from the Base Workspace in the MATLAB struct.
How can I do this?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 9월 24일
The attached example contains the following information which solves the issue:
The following MATLAB code is used to create the struct:
initBUS = Simulink.Parameter;
myDictionaryObj = Simulink.data.dictionary.open('testDD.sldd');
initBUS.DataType = 'Bus: myBus';
initBUS.Value = Simulink.Bus.createMATLABStruct('myBus',[],1,myDictionaryObj); %initializes the struct using the 'scope' property to search for the type in a data dictionary
initBUS.Value.a = evalin('base','aVar'); %gets data from Base Workspace
initBUS.Value.b = evalin('base','bVar'); %gets data from Base Workspace
clear myDictionaryObj
The following property is used to get the Bus type from the Data Dictionary:
After that you simply only have to add the variable initBUS in the Unit Delay mask as follows:
and finally the simulation result is correctly initialized:
If anything is unclear please consider contacting the technical support team for further assistance.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Model Editing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by