- ‘getActiveConfigSet’ : https://www.mathworks.com/help/simulink/slref/getactiveconfigset.html
- 'setActiveConfigSet' : https://www.mathworks.com/help/simulink/slref/setactiveconfigset.html
- 'dir' : https://www.mathworks.com/help/matlab/ref/dir.html
How can I change the configuration of several slx files in a folder?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Iñaki Eizaguirre
le 15 Jan 2024
Réponse apportée : Lokesh
le 15 Jan 2024
I'd like to know how can I change the configuracion of several models that I've got in a folder without opening each of them. Currently, I'm doing this by hand but I'd like to automate this.
For example, I have several with this kind of configuration:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1590956/image.png)
So, I'd like to flick through all the slx files, check their configuration and set it to "Reference" instead of Configuration1
Regards.
0 commentaires
Réponse acceptée
Lokesh
le 15 Jan 2024
Hi Iñaki Eizaguirre,
As per my understanding, you're looking to automate the process of updating the configuration set for several Simulink models (.slx files) without the need to open each file manually.
To achieve this you can utilise MATLAB scripting. Refer to the following sample code snippet that will change the configuration sets of simulink files in a folder:
% Set the directory containing the .slx files
modelDirectory = 'path_to_your_models_folder';
% Change MATLAB's current directory to the models directory
cd(modelDirectory);
% Retrieve a list of all .slx files in the directory
modelFiles = dir('*.slx');
% Loop through each .slx file in the directory
for k = 1:length(modelFiles)
% Extract the model name without the file extension
[filePath, modelName] = fileparts(modelFiles(k).name);
% Load the model into MATLAB's memory without opening the Simulink UI
load_system(modelName);
% Get the active configuration set of the loaded model
cfgSet = getActiveConfigSet(modelName);
% If the active configuration set is not 'Reference', update it
if ~strcmp(cfgSet.Name, 'Reference')
% Set the active configuration set to 'Reference'
setActiveConfigSet(modelName, 'Reference');
end
% Save the model with the updated configuration set
save_system(modelName);
% Close the model without saving again
close_system(modelName, 0);
end
Please refer to the following MathWorks documentation to know more about:
I hope this resolves your query.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interactive Model Editing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!