Opened 10 years ago
Closed 10 years ago
#2919 closed defect (invalid)
Call model.variable with a parameter
Reported by: | hed204 | Owned by: | Adeel Asghar |
---|---|---|---|
Priority: | high | Milestone: | 1.9.1 |
Component: | Frontend | Version: | trunk |
Keywords: | Cc: |
Description
Hi everybody,
I searched a solution for it whithout succes...
there is my problem :
I have in a model two Inertia (Inertia1, Inertia2)
I would like to do this :
for i in 1:2 loop M[i]= "Inertia" & i & ".J"; end for;
I look for the result M[1]=Inertia1.J and M[2]=Inertia2.J
Thanks for your help.
Hugo
Change History (5)
comment:1 by , 10 years ago
comment:3 by , 10 years ago
I think hed204 wants to simulate several models based on the M[i] name he creates but that doesn't work from normal Modelica you need scripting for that. And I'm not even sure you can do it with scripting, do we have a function that converts from String to TypeName?
comment:4 by , 10 years ago
Hi,
Actually I have a model with some Rotationnal.Inertia in. I would like to create a matrix with all inertia (Inertia(number).J). So I did a "for loop"
"Inertia" + String(i) + ".J" works.
But
M[i]="Inertia" + String(i) + ".J"
doesn't work because Real=String
So I am looking for a function to convert a String to a Real (@Adrpo I think that's exactly what you said)
comment:5 by , 10 years ago
Component: | OMEdit → Frontend |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Modelica does not support meta-programming. You cannot concatenate strings to create a variable name.
If you want to loop over an array, declare your variables as arrays:
Intertia intertia[2]; equation for i in 1:2 loop m[i] = intertia[i].j; end for;
I don't understand what you want to do. Share complete model.