필터 지우기
필터 지우기

How can I find duplicate sub systems in model using m-script

조회 수: 3 (최근 30일)
gvreddy
gvreddy 2015년 5월 7일
답변: Nobel Mondal 2015년 5월 13일
Hello,
I want to find duplicate sub systems in model. For example, I have sub system like shown image.
As we can see, duplicate sub system2 is created even though there is no IO changes.
so my interest is to find these kind issues in model using MATLAB commands.
Here is my code as of now:
subSystemHandles = find_system(bdroot,'BlockType','SubSystem');
for k=1 : length(subSystemHandles)
allSubSystem = get_param(subSystemHandles(k),'Name');
eachSubSystem = get(gcbh);
inPortHandles = eachSubSystem.LineHandles.Inport;
inPortNames=get(inPortHandles,'Name');
outPortHandles = eachSubSystem.LineHandles.Outport;
outPortNames=get(outPortHandles,'Name');
end
Here I am trying to read Names of Inport and OutPort using get_param but I am not getting names.
Please, Could some one help me on this?
  댓글 수: 1
Nobel Mondal
Nobel Mondal 2015년 5월 13일
편집: Nobel Mondal 2015년 5월 13일
From what I understand, if a particular SubSystem block has the following blocks within - it would be flagged as redundant.
1. Matching ports and port-blocks within.
2. A single SubSystem block.
3. No other blocks.
Would you agree that this is the problem you're trying to solve?

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

채택된 답변

Nobel Mondal
Nobel Mondal 2015년 5월 13일
This below code should work for reasonably simple subsystems. I haven't tried for any complex ones - like with triggered input.
mdl = 'MySubSys';
load_system('MySubSys')
allBlks = find_system(mdl, 'Type', 'block', 'BlockType', 'SubSystem');
flags = zeros(1,length(allBlks));
for k=1:length(allBlks)
currentPorts = get_param(allBlks{k}, 'Ports');
insideBlks = find_system(allBlks{k}, 'SearchDepth', 1, 'Type', 'block');
insideBlkType = get_param(insideBlks, 'BlockType');
insideIPnum = length(find(strcmp(insideBlkType, 'Inport')));
insideOPnum = length(find(strcmp(insideBlkType, 'Outport')));
insideSSNum = length(find(strcmp(insideBlkType, 'SubSystem')));
insideRestNum = length(insideBlkType)- insideIPnum - insideOPnum - insideSSNum;
if insideIPnum==currentPorts(1) && insideOPnum==currentPorts(2) ...
&& insideSSNum==2 && insideRestNum==0
flags(k)=1;
end
end
ids = find(flags(:)==1);
redundantSubSys = allBlks(ids);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by