
function sl_customization(cm)
  %% Register custom menu function.
  cm.addCustomMenuFcn('Simulink:SimulationMenu', @getMyMenuItems);
end

function schemaFcns = getMyMenuItems(~) 
  schemaFcns = {@getSimOnCluster}; 
end

function schema = getSimOnCluster(~)
  schema = sl_action_schema;
  schema.label = 'Simulate as Batch Job';
  schema.statustip = 'Simulate as Batch Job';
  schema.accelerator = 'Ctrl+alt+t';
  schema.autoDisableWhen = 'Busy';
  schema.callback = @simAsBatchJob; 
end

function simAsBatchJob(callbackInfo)
% Get name
mdl = get(callbackInfo.model,'Name');
% Get all the files needed by the model
fList = dependencies.fileDependencyAnalysis(mdl);
% Send batch job to cluster
c = parcluster;
nOutputs = 1;
inputArgs = {mdl};
j = batch(c, @sim, nOutputs, inputArgs,...
    'attachedfiles',fList,...
    'AutoAttachFiles',false,...
    'CurrentFolder','.');

id =j.ID;
assignin('base',['job' num2str(id)],j);

disp(' ')
disp(['<a href="matlab: job' num2str(id) '">job' num2str(id) '</a>'...
    ' created on cluster: ' c.Name])
disp(' ')
end





