Struct as mask input
조회 수: 34 (최근 30일)
이전 댓글 표시
Hello, I would like to have a struct as a mask input to a Model Reference. I will have multiple identical model references in my model. When I currently try to modify the mask parameter to use a struct, I get the following error:
"Variable 'blah' has ben deleted from the base workspace."
The struct contains information for a large number of blocks and I am trying to have the blocks extract the information from the struct in the normal way (e.g., Block param: blah.field.block_param_value).
Everything works if I have the struct defined in the base workspace and then have the sub-model (used by the model reference) use that directly. However, this does not allow me to use multiple identical model references because they would all point to the same struct in the base workspace.
I have looked at a number of other posted questions asking about this issue and have read that this is possible but without in-depth information as to how.
The following asks this but the answer does not work for me-
This references it but was never answered-
Other resources suggest using a non-virtual bus, but I am unsure how that accomplishes this goal if I'd like to access the fields in a struct-like fashion.
Very much appreciate the help ahead of time :)
댓글 수: 4
채택된 답변
Paul
2024년 1월 6일
I did the following:
1) created a model child.slx. It has an Inport -> Gain -> Outport. The gain parameter is set to 'parameters.gain' (no quotes)
2) In the model workspace of child.slx, I created the Matlab variable 'parameters'. I this by creating the parameters struct in the base workspace, i.e., parameters.gain = 1, and then copied 'parameters' from the base workspace into the model workspace of child.slx. I couldn't figure out how to create a struct variable in the child.slx model workspace directlly.
3) In child.slx, I opened the Model Data Editor and checked the Argument box for 'parameters' .
4) Created model parent.slx. Added two model blocks, each set to reference child.slx.
5) In the first model block I set the Value field for 'parameters' under the Instance parameters tab to 'params1'.
6) In the second model block I set the Value field for 'parameters' under the Instance parameters tab to 'params2'.
7) In the base workspace, I created params1 and params2
params1.gain = 5;
params2.gain = 10;
8) Simuated the model. The gains of 5 and 10 flowed down to the Gain blocks in the child.slx models as expected.
I'm not too familiar with Simulink Parameters, so didn't try to make it work that way.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Author Block Masks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!