how to get all the .mdl file in a folder without extension in matlab

1 view (last 30 days)
how to get all the .mdl file in a folder without extension in matlab and also save the .mdl to slx. can anyone help please. Save_system modleneamewoext modelname.slx
I want all the .mdl files without ext in a folder

Answers (1)

Arjun
Arjun on 4 Mar 2025
I see that you want to convert all the '.mdl' files in a folder to '.slx' files.
You can do so by using the following steps:
  1. Get a list of all the '.mdl' files in a folder by using 'dir' and 'fullfile' functions of MATLAB
folderPath = 'PathToYourFolder';
% Get a list of all .mdl files in the folder
mdlFiles = dir(fullfile(folderPath, '*.mdl'));
2. Loop through all the files and make necessary changes as listed in the code segment below
% Loop through each .mdl file
for k = 1:length(mdlFiles)
% Get the name of the file with the extension
mdlFileName = mdlFiles(k).name;
% Remove the extension to get the model name without extension
[~, modelName, ~] = fileparts(mdlFileName);
% Load the model
load_system(fullfile(folderPath, mdlFileName));
% Save the model as a .slx file
save_system(modelName, fullfile(folderPath, [modelName, '.slx']));
% Close the model
close_system(modelName, 0);
end
Kindly refer to the documentation of the functions used above for better understanding:
I hope this will help!

Categories

Find more on Programmatic Model Editing 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!