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

조회 수: 4 (최근 30일)
Priya Mahalakshmi
Priya Mahalakshmi 2021년 4월 27일
답변: Arjun 2025년 3월 4일
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

답변 (1개)

Arjun
Arjun 2025년 3월 4일
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!

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by