How to pass a struct to a model reference instance?

조회 수: 10 (최근 30일)
Christopher Fromme
Christopher Fromme 2023년 11월 22일
편집: Stefanie Schwarz 2024년 5월 29일
Hi all,
I have a Simulink Parameter containing a struct that I would like to pass on to a model reference instance.
Using the parameter from the basae workspace is no problem, but I need to use different parameters for the individual instances.
My idea was to use the instance parameters, but it seems like I cannot use a struct there.
Data type "auto" is not allowed and struct is not available.
The parameters I'd like to pass on look like this:
Is there a way to use a struct as instance parameter?
Or is there maybe a totally different approach?
Any help would be highly appreciated. :)
Thanks!
Christopher

채택된 답변

Christopher Fromme
Christopher Fromme 2023년 11월 24일
편집: Stefanie Schwarz 2024년 5월 29일
I managed to solve this by adding the parameter programmatically.
Initially, I had a structure containing Simulink Parameters, that I would like to use as Model Instant Parameter:
ctrl1_struct =
struct with fields:
tholdoff: [1×1 Simulink.Parameter]
vdc2: [1×1 struct]
demagPeriod: [1×1 Simulink.Parameter]
itr2min: [1×1 struct]
But this does not work. You can add it to the model workspace but not use it as argument.
The solution is to convert it into a Simulink Parameter, which has the structure as value:
ctrl1 = Simulink.Parameter(ctrl1_struct)
ctrl1 =
Parameter with properties:
Value: [1×1 struct]
CoderInfo: [1×1 Simulink.CoderInfo]
Description: ''
DataType: 'struct'
Min: []
Max: []
Unit: ''
Complexity: 'real'
Dimensions: [1 1]
Then you can add it to the workspace:
myModelWorkspace = get_param('app_dcdc_prio1Ctrl','ModelWorkspace');
assignin(myModelWorkspace, 'ctrl1', ctrl1);
Now it is usable as argument and thus as model instance parameter.

추가 답변 (1개)

madhan ravi
madhan ravi 2023년 11월 23일
편집: madhan ravi 2023년 11월 23일
elems(1) = Simulink.BusElement;
elems(1).Name = 'Chirp';
elems(2) = Simulink.BusElement;
elems(2).Name = 'Sine';
Sinusoidal = Simulink.Bus;
Sinusoidal.Elements = elems;
Sinusoidal1 = Simulink.Bus.createMATLABStruct('Sinusoidal'); % structure must be a Bus datatype
%Set the values for the parameter
Sinusoidal1.Chirp = 0;
Sinusoidal1.Sine = 1;
myParameter = Simulink.Parameter(Sinusoidal1) % pass the parameter values to the parameter object
myParameter.DataType = 'Bus: Sinusoidal'
  댓글 수: 1
Christopher Fromme
Christopher Fromme 2023년 11월 24일
Thanks a lot for your reply.
Unfortunatelly, I would like to use the struct directly for block parameters.
But I think I found a solution now, I'll post it as answer here.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Component-Based Modeling에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by