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

4 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Arjun
Arjun il 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!

Categorie

Scopri di più su Programmatic Model Editing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by