Convert from MDL to SLX in a Project and Preserve Revision History

Project Tools for Migrating Model Files to SLX

A project helps you upgrade model files from MDL format to SLX format. The default file format for Simulink® models in R2012b and subsequent releases is SLX. You can use the project integrity checks to automatically add the new SLX file to your project, remove the MDL file from the project, and preserve the revision history of your MDL file with the new SLX file. You can then commit your changes to source control and maintain the continuity of your model file history.

Open the Airframe Example Project

Create and open a working copy of the airframe project using Git™ source control.

sldemo_slproject_MDL_to_SLX;
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.

Find All MDL Files in the Project and Convert to SLX

In the models folder, check if this project contains models saved in MDL format.

To find all the MDL files in this project and resave them as SLX files, use the project API:

project = currentProject;
allProjectFiles = project.Files;
for fileIndex = 1:numel(allProjectFiles)
    projectFile = allProjectFiles(fileIndex);    
    [folder, name, ext] = fileparts(projectFile.Path);
    if strcmp(ext, '.mdl')
        % This is a MDL file. Load it and then save as an SLX file.       
        mdlModel = fullfile(folder, [name + ext]);
        slxModel = fullfile(folder, [name + '.slx']);
        load_system(mdlModel);
        % Save a new copy of this file in SLX format:
        save_system(name, slxModel);
        close_system(name,0);
    end
end

To see the results, in the Files view, change the view from Project ( number of files ) to All. Expand the models folder. Simulink® saves the model in SLX format and creates a backup file by renaming the MDL file to filename.mdl.releasename, for example, AnalogControl.mdl.r2019b. The project also reports the original name of the MDL file as missing.

Run the Project Checks

To resolve these issues, on the Project tab, click Run Checks > Check Project to run the project integrity checks. The checks look for MDL files converted to SLX and offer automatic fixes if that check fails. Click the Fix button to view recommended actions and decide whether to make the changes.

The Missing Files dialog box offers to remove the missing MDL file from the project and add the new SLX file to the project.

Project checks rerun after you click Yes to perform the fix. Close the Project Integrity Checks dialog box.

Verify Changes After Upgrade to SLX

Click the Modified files view of the project. Project checks added the newly created SLX files to the project and scheduled the original MDL files for removal.

Commit Changes and Verify Revision History

On the Project tab, in the Source Control section, click Commit. Enter a comment for your submission in the dialog box, for example, Convert to SLX, and click Submit. Right-click the new SLX model. Select Source Control > Show Revisions. In the File Revisions dialog box, verify that the previous revision is filename.mdl, for example, AnalogControl.mdl. The revision history of the previous model file is preserved with the new SLX file.

Further Information

Project Management