MATLAB Answers

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

25 ビュー (過去 30 日間)
Matteo Gnudi
Matteo Gnudi 2019 年 11 月 25 日
回答済み: Divya Gaddipati 2020 年 1 月 10 日
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 件のコメント

Nicolas B.
Nicolas B. 2019 年 11 月 25 日
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?

サインイン to comment.

回答 (2 件)

Divya Gaddipati
Divya Gaddipati 2020 年 1 月 10 日
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!

  0 件のコメント

サインイン to comment.

Matteo Gnudi
Matteo Gnudi 2019 年 12 月 6 日
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.

  0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。




Translated by