필터 지우기
필터 지우기

Overwrite exisiting simulink file using script

조회 수: 5 (최근 30일)
Harish
Harish 2023년 12월 28일
댓글: Harish 2024년 1월 4일
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
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.
Harish
Harish 2023년 12월 28일
Hi,
Thanks for the reply. I am using R2023b. I want to use save_system()

댓글을 달려면 로그인하십시오.

채택된 답변

Harald
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
Harish
Harish 2023년 12월 29일
Hi,
Thanks for the answer. I am trying to use new_system(fname) first and then save_system(fname). On the next run, eventhough I delete the file manually, it says that 'fname' file already loaded.
Where exactly is the file loaded once I use new_system()?. How Can I delete it if it exists? Does bdIsLoaded work?
Harald
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
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!
  댓글 수: 1
Harish
Harish 2024년 1월 4일
Hi Rishi,
Thankyou for the Answer. It helped. :-)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by