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
채택된 답변
Kaustubha Govind
2012년 7월 30일
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
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. :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
