Clear Filters
Clear Filters

Get the current model which from code is being generetated using slbuild

4 views (last 30 days)
In one of my project I would like to add some kind of progress bar to the code generation process, since other members would like to use it, who are not familiar with this process.
I am using slbuild , since it is recommended. During the code generation many information are sent to the command window , including which model is being built. Is it possible to attach some kind of progress bar to this?

Answers (1)

Hari on 17 Nov 2023
Hi Gergely,
I understand that you would like to add a progress bar to the code generation process using "slbuild" in MATLAB to provide visual feedback on the progress of the code generation, specifically indicating which model is currently being built.
To achieve this, one possible approach is to modify the "slbuild" function to include a progress bar. However, the "slbuild" function does not provide built-in support for progress bars. Therefore, we need to implement it using "waitbar" function in MATLAB.
Here's an example of how you can implement a progress bar using "slbuild":
% Get the list of models to be built
modelList = find_mdlrefs(bdroot);
% Create a progress bar
progressBar = waitbar(0, 'Building models...');
% Loop through the models
for i = 1:length(modelList)
% Get the current model name
modelName = modelList{i};
% Update the progress bar message
waitbar(i/length(modelList), progressBar, strcat('Building ', modelName, '...'));
% Call slbuild for the current model
% Close the progress bar
In this example, we first define an array of model names that need to be built. You can modify this array to include the models specific to your project.
Next, we loop through the models and update the progress bar message using the "waitbar" function within the loop. The progress value is calculated as "i/length(models)", where "i" is the current iteration index.
Inside the loop, we call "slbuild" for the current model using "slbuild(models(i))". Finally, after the loop, we close the progress bar using the close function. By following the above steps you would be able to add a progressbar for the code generation processing showing which models are currently being build.
Refer to the documentation of "slbuild" and "waitbar" for more information:
Hope this helps!


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!