How do I export Simulink projects in a previous version in an automated way?
120 views (last 30 days)
Show older comments
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.
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?
Answers (4)
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.
load_system(file);
info = Simulink.MDLInfo(file);
newName = [modelName '_' targetVersion ext];
newFile = fullfile(modelFilepath, newName);
if exist(newFile, 'file')
error('Remove existing file "%s" and rerun', newFile);
end
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]);
otherwise
result = [];
end
end
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
on 22 Oct 2020
As of R2020b, you can export an entire project using the following documentation link:
1 Comment
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?
Eeman Zafar
on 9 Nov 2023
Can anyone tell me how can convert *.m file to any old version. I am using Matlab 2018b version and I want to convert the *.m files to version 2017a.
0 Comments
See Also
Categories
Find more on Project Management 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!