Struct as mask input
35 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Prestonr
el 6 de En. de 2024
Comentada: Prestonr
el 16 de En. de 2024
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 comentarios
Respuesta aceptada
Paul
el 6 de En. de 2024
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.
Más respuestas (1)
Ver también
Categorías
Más información sobre Author Block Masks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!