How do I export Simulink projects in a previous version in an automated way?

168 views (last 30 days)
Is there a way to save Simulink projects by exporting them in a previous version just by pressing "save" button and without always pressing "export to... previous version button"?
( Versions: R2019b -> R2016b )
  1 Comment
Nicolas B.
Nicolas B. on 25 Nov 2019
I haven't seen such an option. I am also sceptical about whether there is such a function. What was previously Simulink Project is now Matlab Project... That's a big change.
Have you tried simply to open the MATLAB project with R2016b? What happens?

Sign in to comment.

Answers (3)

Divya Gaddipati
Divya Gaddipati on 10 Jan 2020
A possible current workaround is to manually export all the models in the desired release, or do it programmatically with the function Simulink.exportToVersion, and then create a new project.
Alternatively, it is possible to run a custom task with the Simulink Project that tries to export all the model files in the project to an older version.
Here is a small code that exports a simple model hierarchy to R2016b.
function result = exportToPreviousVersion(file)
%exportToPreviousVersion - This example uses a Simulink Project custom task
% to attempt export all Simulink model files to a previous version of
% MathWorks tools.
targetVersion = 'R2016b';
[modelFilepath, modelName, ext] = fileparts(file);
switch ext
case {'.mdl', '.slx'}
% Close all models first -- this code can error if hierarchies of
% model references are open with unsaved changes, for example.
info = Simulink.MDLInfo(file);
newName = [modelName '_' targetVersion ext];
newFile = fullfile(modelFilepath, newName);
if exist(newFile, 'file')
error('Remove existing file "%s" and rerun', newFile);
exportedFile = Simulink.exportToVersion(modelName,newFile,targetVersion);
close_system(modelName, 0);
pause(1); % Just to let the file system catch up
movefile(file, [file '.' info.ReleaseName], 'f');
% Could add the old back up file to the project here
movefile(exportedFile, file, 'f');
result = sprintf('Created "%s" for use in %s, back up file in "%s"', ...
file, targetVersion, [file '.' info.ReleaseName]);
result = [];
After opening the project, in the Simulink Project tab window please select 'Custom Task' and then browse to the MATLAB function 'exportToPreviousVersion.m'. Then, click on Run Task.
In so doing, all the models will be exported to R2016b and a backup copy in current MATLAB version is saved.
For further information on custom tasks, please refer to the link below:
Hope this helps!

Andrew Grabowski
Andrew Grabowski on 22 Oct 2020
As of R2020b, you can export an entire project using the following documentation link:
  1 Comment
Buse Özer
Buse Özer on 4 Jan 2021
Hi, I have an simulink model made with R2020b and it includes blocks calculations etc.Can I export it to older versions without losing the blocks?

Sign in to comment.

Matteo Gnudi
Matteo Gnudi on 6 Dec 2019
After exporting the simulink project in version R2016b, a colleague of mine managed to open it with R2016b and it worked: The fact is that I would like to find a way to save all the future file .slx in R2016b version in an automated way, in order to allow other colleagues of mine to work on my Simulink project via their Simulink version which is R2016b.


Find more on Interactive 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!