function PrintModel(ModelName)
% Print all the subsystems of a SIMULINK model as Postscript files which can also be viewed.

% Cell array a contains the names of the blocks in the entire system
open_system(ModelName)

FilePrefix = ModelName;
blks = find_system(gcs,'Type','block');
listblks = get_param(blks,'BlockType');
Indices = strmatch('SubSystem',listblks);
AllSubsystems = char(blks(Indices,:));

print(['-s' ModelName],'-deps2','-tiff',[ModelName num2str(1)]);

for i = 1:length(Indices)
    SubsystemName = deblank(AllSubsystems(i,:));
    try
        open_system(SubsystemName)
        print(['-s' SubsystemName],'-deps2','-tiff',[FilePrefix num2str(i+1)])
        close_system(SubsystemName)
    catch
        disp(['Subsystem --> "' SubsystemName '" was not printed'])
    end
end

close_system(ModelName)