0

我希望函数返回“根”和下面所有子系统的路径。我还不知道该怎么做,这是我的尝试,还没有运行它,因为我需要找出所有功能来做列表以及附加和获取子系统路径等等。但我只是想问一下这是否是正确的方法,以便我可以继续搜索这些功能,或者是否存在执行此操作的功能或部分功能?

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
4

0 回答 0