Viktor Mellgren
Viktor Mellgren

Reputation: 4506

simulink detect gcs if subsystem

I have this function, but it breaks when gcs is a subsystem.

function dest = save(path)
    dest = save_system(gcs,path)
end

i would want it to be something like:

function dest = save(path)
    item = gcs
    if(gcs.isSubsystem)
        dest = //do subsystem stuff
    else
        dest = save_system(gcs,path) 
end

Upvotes: 0

Views: 180

Answers (2)

Phil Goddard
Phil Goddard

Reputation: 10772

The safest way to check this is

if strcmp(bdroot(gcs),gcs)
   % I'm the main model
else
   % I'm a subsystem
end

Upvotes: 3

Viktor Mellgren
Viktor Mellgren

Reputation: 4506

function dest = save(path)
    if isempty(strfind(gcs,'/'))
        dest = save_system(gcs,path)
    else
        //do subsystem stuff
    end
end

Upvotes: 0

Related Questions