How to configure set_param() per instance for arrays
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ludo Houben
el 18 de Dic. de 2023
Comentada: Ludo Houben
el 3 de En. de 2024
I have a function 'deep' within a model that is called as an array. Each instance of this function needs a different value for its parameter. I already found that you can set the parameter with the set_param() command. This worked fine as long as I only had 1 instance in my array. But I need multiple. How can I set each instance its own value?
In more details. I have an array of 'DEV_DspBox' which receives its data from a PLC.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1571532/image.png)
Setting a single value for the parameter works with this:
set_param('PlayGround_Model/DEV_DspBox[n]/DEV_DspBox/DEV_DspProbe_A/DEV_DspProbeSensorLeft/fbTriggerBuffer', 'nParNrOfDataRecords', "5");
But I need to be able to set the 'nParNrOfDataRecords' of the fbTriggerBuffer for each instance of DEV_DspBox separate. The value is depending on a distance of the sensor to a reference point. Each 'probe' is located within a different hardware position, so the buffer size is depending on the distance of the 'probe' to the reference point. Causing that the parameter needs to be different for each instance. How to do this?
Thanks for any suggestions in advance.
Cheers
Ludo
2 comentarios
madhan ravi
el 19 de Dic. de 2023
Ludo could you please illustrate with an example? Since we don’t see the model complete , it’s hard to follow. When you mean single value, what do you mean? You want to make it a vector instead of a scalar? With your code you set nParNrOfDataRecords 5 but you want for example 5, 10? Is that right?
Respuesta aceptada
Fangjun Jiang
el 19 de Dic. de 2023
Editada: Fangjun Jiang
el 19 de Dic. de 2023
This is "For Each Subsystem". You need to know how to use it. See the document and examples.
set_param() is not the correct way to do it. Instead, you give that block parameter a variable name, say, MyParam. Usually, you set MyParam=5 in workspace and then it is all set.
When using "For Each Subsystem" with N=5 for example, you set MyParam=[1 2 3 4 5]. Then MyParam=1 will be passed to the subsystem when N=1, MyParam=5 will be passed to the subsystem when N=5. This is called parameter partition.
See the double loop icon of the Inport and Outport block? That means that signal is "partitioned".
Double click that "For Each" block will show you how to "partition" signal and parameter.
5 comentarios
Fangjun Jiang
el 19 de Dic. de 2023
By which block is this parameter used?
Anyway, Click that "Working with For Each Subsystems" link on the "ForEach" dialog window, it will bring up the document and example. You will need to follow the section of "Model Parameter Variation Without Changing Model Structure".
Más respuestas (0)
Ver también
Categorías
Más información sobre Programmatic Model Editing 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!