How do I export Simulink projects in a previous version in an automated way?
121 ビュー (過去 30 日間)
古いコメントを表示
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.
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?
回答 (4 件)
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.
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
2020 年 10 月 22 日
As of R2020b, you can export an entire project using the following documentation link:
1 件のコメント
Buse Özer
2021 年 1 月 4 日
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
2023 年 11 月 9 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!