Message Boards Message Boards


Component arrays in Diagram View

Posted 3 years ago
3 Replies
2 Total Likes

I have a component array

parameter Integer n = 4    
myComponentType[n] componentArray

And I can set each parameters in the component array with something like

parameter Real[n] params
myComponentType[n] componentArray(param=params)

But this seems very clunky to have to set up a parameter array to specify the individual parameters. I'm sure there's a better way.

Additionally, once I turn the component into an array, I lose the ability to change each component's property in Diagram View. I found in "component properties" that there's a checkbox for "array" but it doesn't update the expression editor.

Screenshots to illustrate:

Array is selected but "n" hasn't evaluated to 4 Array is selected but

The parameter array I'm using as a work around is resized to 4 The parameter array I added is resized

The parameter for the component array is not detected as an array the parameter for the component array is not detected as an array

3 Replies


As mentioned in your other post (resizing arrays) when you make a Class an array, the parameters must be entered as arrays in the form {1,2,3,4,5} (for a one dimensional array). See the model attached to that post to see an example (including setting the parameters from Mathematica)



Thanks for the reply. I found my error. By setting the parameters of the component array with a local variable array, I overrode SystemModeler's GUI features. In other words, by trying to work around what I thought was a shortcoming just prevented me from seeing the shortcoming never existed :(

So I had

subComponent[n] componentArray(param = localParamArray)
parameter Real[n] localParamArray

which was completely unnecessary. All I needed was

subComponent[n] componentArray

This is kind of embarrassing and apologize for taking up space on the forums with a noob question. But thanks again for taking the time to respond!


No problem. Its not really a noob question. Component arrays are difficult because there is not much information (or documentation) on using them. I had to talk to @Patrik Ekenberg in Sweden to originally figure out what you can and can't do. Maybe I'll put together a post on uses of component arrays in models. I worked with Patrik to do this post on simulating an array of pendulums. or Maybe we can even get Patrik to put a tutorial up on creating arrays like this and setting values from Mathematica! :)


Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract