Overwrite exisiting simulink file using script
6 ビュー (過去 30 日間)
古いコメントを表示
Hello all,
I am trying to create a simulink file using matlab script with the commands new_system() and save_system(). Unfortunately, this command is unable to overwrite if a file with the same name already exists. I have no problem overwriting the existing files.
Can anyone suggest a way where I can do this?
2 件のコメント
Ganesh
2023 年 12 月 28 日
Could you please give more info on the version you are using and what command you are using? Saving a model with the same name as an existing model seems to work fine with R2023b.
採用された回答
Harald
2023 年 12 月 28 日
Hi,
I suppose you have looked into flags such as OverwriteIfChangedOnDisk? If these don't help, I would resort to checking if the file exists and, if so, deleting it before using the intended commands.
if exist(fname, "file")
delete(fname)
end
Just be sure that you really do not need the old file!
Best wishes,
Harald
2 件のコメント
Harald
2023 年 12 月 30 日
Hi,
the close_system or bdclose commands should help. You may also find it useful to use bdIsLoaded ahead of those.
Best wishes,
Harald
その他の回答 (1 件)
Rishi
2023 年 12 月 30 日
Hey Harish,
I understand that you want to use the 'new_system' function to create a new Simulink model and then save that model using the 'save_system' function.
The function 'new_system' creates a new Simulink model in the memory. It works even if a model with the same name exists, but will throw a warning saying that your model is shadowing another model. Once you use 'save_system' on the new model, it overwrites the older model.
If you are unable to create a new model with the same name, the older model might be open. You can close that model first using the 'close_system' command.
You can learn more about 'new_system', 'save_system' and 'close_system' from the below documentations:
Hope this helps!
参考
カテゴリ
Help Center および File Exchange で Programmatic Model Editing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!