Make simulink custom task run sequentially
2 views (last 30 days)
Show older comments
I have a custom task function that runs fin on a single model but when I run it with Custom Task on all the models in my project I get a problem where for models which are made up of other models the function won't run because the sub models are already opened by the master model.
I could filter the models before running to not select any sub models but as I am not going to be the only person running this script would rather not do this.
Is there a way to force the custom task to run on each of the models sequentially instead of trying to open them in parrallel.
0 Comments
Answers (1)
Karan Singh
on 29 Sep 2023
Hi Reuben,
From what I understand, issue you are facing is related to running a custom task function on multiple models within your project. You are seeking a solution that allows the custom task to run on each model sequentially, rather than trying to open them in parallel.
This can be achieved by using a loop to iterate over the models and calling your custom task function for each model individually. Here's an example of how you can modify your custom task function to run sequentially on each model:
function runCustomTaskOnModels()
% Load the project containing the models
project = loadProject('path/to/your/project.prj');
% Get a list of all the models in the project
models = project.Models;
% Iterate over each model and run the custom task function
for i = 1:numel(models)
model = models(i);
% Call your custom task function for the current model
customTaskFunction(model);
end
end
function customTaskFunction(model)
% Your custom task function implementation
% Perform the necessary operations on the model
% Example: Display the model name
disp(model.ModelName);
% Example: Run finite element analysis on the model
results = solvepde(model);
% Example: Save the results to a file
saveResultsToFile(results);
end
In this example, the “runCustomTaskOnModels” function loads the project and retrieves a list of all the models. It then iterates over each model using a loop and calls the “customTaskFunction” for each model. Inside the “customTaskFunction”, you can perform the necessary operations specific to your task.
Hope this helps!
Karan Singh Khati
0 Comments
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!