0

I want the function to return the "root" and the paths to all the subsystems below. I have yet no clue how to do it, this is my attempt, haven't run it yet because I need to find out all the functions to do lists and appending and getting subsystem paths and so on. But I just wanted to ask if this is the right way to do it so that i can proceed with my searching for these functions, or if there exists functions to do it or parts of it?

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
Will Ness
  • 70,110
  • 9
  • 98
  • 181
Viktor Mellgren
  • 4,318
  • 3
  • 42
  • 75
  • 1
    find_system should give you list of all the SubSystems in the model. – Navan Jul 02 '13 at 16:40
  • 2
    find_system will automatically iterate down the model hierarchy so there's no need for you to do it. Depending on your requirements you may need to use the LookUnderMasks and FollowLinks options. See the doc for find_system for details. – Phil Goddard Jul 02 '13 at 18:07
  • Aah, that's great, will check it out, thanks! I'd accept that as an answer if it was one. – Viktor Mellgren Jul 03 '13 at 08:39
  • @PhilGoddard, I checked out those options, but they do not change the results. I have asked a separeate question for this, since it is not really related. http://stackoverflow.com/questions/17444868/find-system-returns-objects-that-are-not-subsystems-in-simulink – Viktor Mellgren Jul 03 '13 at 10:06

0 Answers0