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

3 次查看(过去 30 天)
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