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

4 visualizaciones (últimos 30 días)
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 comentario
Nobel Mondal
Nobel Mondal el 13 de Mayo de 2015
Editada: Nobel Mondal el 13 de Mayo de 2015
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?

Iniciar sesión para comentar.

Respuesta aceptada

Nobel Mondal
Nobel Mondal el 13 de Mayo de 2015
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);

Más respuestas (0)

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by