Replace a subsystem A with subsytem B on different models

Hi Im trying to replace a subsystem "oldSub" in "model1" with another subsystem "newSub" in "model2". i used this syntaxis, no error occures but no change in "model1" either !!
replace_block('model1','Name','oldSub','model2/newSub')
i updated "model1" using: set_param('model1','SimulationCommand','Update'), that didnt help ...
thx in advance
kinane

 Accepted Answer

Does 'oldSub' exist in the top-level of the model or inside a subsystem? For example, does the following command return any value:
find_system('model1','Name','oldSub','SearchDepth',1)
Also, you need to make sure that both 'model1' and 'model2' are loaded when you run the command(s). You can use the load_system command to load (ie. open in the background) the models.

7 Comments

Yes, both "oldSub" and "newSub" are subsystems beloging to the top level, each in its respective model.
for some reason "find_system('model1','SearchDepth',1,'Name','oldSub')" retun an empty matrix, but "find_system('model1','SearchDepth',1)" does return "oldSub" in the return matrix (array) !!
i will paste a part of the command window so you can see what i mean.
Note: "model1" = "temperaturaventana3" , "oldSub" = "Temperatura exterior"
>> load_system('temperaturaventana3') >> find_system('temperaturaventana3','SearchDepth',1,'Name','Temperatura exterior')
ans =
Empty cell array: 0-by-1
>> find_system('temperaturaventana3','SearchDepth',1)
ans =
'temperaturaventana3'
'temperaturaventana3/Calefactor'
.
.
.
'temperaturaventana3/Sum'
'temperaturaventana3/Temperatura
Habitación'
'temperaturaventana3/Temperatura
exterior'
'temperaturaventana3/Velocidad aire'
'temperaturaventana3/Out1'
.
.
.
Thank you for your answer on such a short notice.
kinane
Ah! It looks like you have the return (\n) character between 'Temperatura' and 'exterior'. You could try:
find_system('temperaturaventana3','SearchDepth',1,'Name','Temperatura\nexterior')
(Note: You might need to add a blank-space character between the words if it exists in the block name)
Hi Kaustubha, i did take out all blanks. "Replace Dialog" window is promped, but still no effect on model. the reason im trying to replace blocks is as follow:
im running 2 "parallel" simulations of 2 similar models. Both models got a subsystem block which is basicly a sine wave signal (i.e. temperaturaventana3).
what i would like to do is, to pause the main simulation of model1 "set_param(bdroot,'SimulationCommand','Pause')", then "sim()" a specific condition on model2. But for that to work i will need, to initiate the sine wave block on model2 with the Phase value of the analogous block on the main simulation when paused. i couldnt find a way to catch the Phase value when main simulation pauses.
Is there a command or a specific parameter that i can use in order to get Phase during runtime ?
Does the replace work when neither model is in paused state? (although I think it should be sufficient if the model you are writing to is not in the middle of simulation)
Since the "Phase" is a parameter of the Sine Wave block, you can use get_param('model/Sine Wave', 'Phase') to get its value. Note that this returns the parameter value as a string, so you may need to use STR2NUM or the EVALIN command to get the actual value (EVALIN is needed if the value of the phase is actually the name of a variable that is present in the base workspace).
get_param() returns the initial phase of the signal, which is a constant value. I ended up calculating the new value then using set_param() to modify "Phase" in the second simulation just before it starts. this is what i did: after each pause of the first simulation, i calculate the phase "time elapsed since simulation starts" * Frequency + Phase, in other words, tout(lastindex)*Frequency+Phase. set_param with this new Phase value in my second simulation, then start the simulation. i did notice that what i get is a string, so better watch out for that, if using "pi" and "/" in parameters fields, none numerical values, use eval().
Thanks again Kaustubha.
Just a word of caution - is "tout" the variable logged by the model? I don't know if there is a guarantee that this variable is written to at the end of every time-step. There is a possibility that the value is maintained in an internal buffer and updated to the workspace once in a while.
yes it is,and yes, in my case i read "tout" when i pause simulation, still it does get written after each time-step. :)

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!