Algorithm 在Simulink中递归获取子系统
我希望函数返回“根”和下面所有子系统的路径。我还不知道怎么做,这是我的尝试,还没有运行它,因为我需要找出所有要做列表的函数,以及附加和获取子系统路径等等。但我只是想问一下,这是否是正确的方法,这样我就可以继续搜索这些函数,或者是否有函数可以完成它或它的一部分Algorithm 在Simulink中递归获取子系统,algorithm,search,recursion,path,simulink,Algorithm,Search,Recursion,Path,Simulink,我希望函数返回“根”和下面所有子系统的路径。我还不知道怎么做,这是我的尝试,还没有运行它,因为我需要找出所有要做列表的函数,以及附加和获取子系统路径等等。但我只是想问一下,这是否是正确的方法,这样我就可以继续搜索这些函数,或者是否有函数可以完成它或它的一部分 function dest,paths = SaveRootAndBelow(path) entitytosave = gcs; if strcmp(bdroot(entitytosave),entitytosave)
function dest,paths = SaveRootAndBelow(path)
entitytosave = gcs;
if strcmp(bdroot(entitytosave),entitytosave)
% I'm the main model
dest = save_system(entitytosave,path);
paths = getPaths(entitytosave)
else
% I'm a subsystem
newbd = new_system;
open_system(newbd);
% copy the subsystem
Simulink.SubSystem.copyContentsToBlockDiagram(entitytosave, newbd);
dest = save_system(newbd,path);
paths = getPaths(newbd)
% close the new model
close_system(newbd, 0);
end
end
function paths = getPaths(root)
paths = []
subsystems = find_system(modelName, 'BlockType', 'SubSystem')
foreach subsystem in subsystems
paths.append(subsyspath)
paths.append(getPaths(subsystem))
end
end
find_系统应该为您提供模型中所有子系统的列表。find_系统将自动向下迭代模型层次结构,因此您无需这样做。根据您的要求,您可能需要使用LookUnderMasks和FollowLinks选项。有关详细信息,请参阅find_系统的文档。啊,太好了,我会查看的,谢谢!如果答案是肯定的,我会接受的。@PhilGoddard,我检查了这些选项,但它们不会改变结果。我已经为此问了一个separeate问题,因为它实际上并不相关。