필터 지우기
필터 지우기

open_system() not working with Model Reference

조회 수: 11 (최근 30일)
Christian
Christian 2023년 8월 9일
편집: Christian 2023년 8월 18일
Hello,
I am using Simulink R2022b.
Currently I am trying to use the open_system() in the Command Window for a top level model that references other models using the Block "Model" from Simulink/Ports&Subsystems library.
However using :
open_system('TOP_LEVELSystem/Model (NAME_REF_MODEL)/SubsystemXYZ')
does not work because in the top level system it only identifies 'TOP_LEVELSystem/Model' as a block, but nothing below that.
Is there any workaround ? Thank you very much !

채택된 답변

Fangjun Jiang
Fangjun Jiang 2023년 8월 10일
You need to get the name of the referenced model first and then open the model separately.
RefModel=get_param('TOP_LEVELSystem/Model','ModelName');
open_system(ModelName);
open_system(fullfile(ModelName,'SubsystemXYZ'))
  댓글 수: 1
Christian
Christian 2023년 8월 18일
편집: Christian 2023년 8월 18일
Thank you Fangjun ! This works, had to adjust your code a little :
RefModel=get_param('TOP_LEVELSystem/Model','ModelName');
open_system(strrep(fullfile(RefModel,'SubsystemXYZ'),'\','/'));

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sara Nadeau
Sara Nadeau 2023년 8월 11일
If you want to open the model within the context of the model hierarchy, you can create a Simulink.BlockPath object and then use the open function to open the model to the location specified in the Simulink.BlockPath object.
  댓글 수: 1
Christian
Christian 2023년 8월 18일
편집: Christian 2023년 8월 18일
Thank you Sara for your reply ! Still I need to get the referenced Models name, like in Fangjuns reply.
So I cannot use :
Simulink.BlockPath = ('TopSystem/Model (RefModelName)/SubsystemXYZ')
instead I have to use:
RefModel=get_param('TOP_LEVELSystem/Model','ModelName');
bp=Simulink.BlockPath(strrep(fullfile(RefModel,'SubsystemXYZ'),'\','/'));
open(bp);
Therefore I do not see any benefit in this method. Even though in Simulink the path is displayed like this :
'TopSystem/Model (RefModelName)/SubsystemXYZ'
It does not work with the BlockPath.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by