Create model only if it doesn't exist

My script has this structure :
sas='Model'; new=new_system('sas') open_system('sas')
[...]
save_system('sas') close_system('sas')
Now the questio is:
I can need to work more on the system that I close, I can need to add other blocks. I would like to reach this purpose
1- Open system that I had closed and saved. Now if I run the script the second time, It says "A system named 'sas'already exists. Is there a function similar to fopen for files, so that I could delete new_system?

댓글 수: 1

Chiara
Chiara 2013년 5월 15일
idea: if I declare a variable set to 0 when I run the script for the first time, then I increment to 1. I could close creation of system in if-else code, so when the variable is 1, it doesn't creat but It opens!

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

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 15일
편집: Azzi Abdelmalek 2013년 5월 15일

1 개 추천

if isempty(which('Model.mdl'))
new=new_system('Model')
end
open_system('Model')

댓글 수: 2

Chiara
Chiara 2013년 5월 15일
thank you very much! I used the same structure, even to use other variables declared when I run the script the first time.
Kaustubha Govind
Kaustubha Govind 2013년 5월 15일
편집: Kaustubha Govind 2013년 5월 15일
I would make that:
isempty(which('Model.mdl')) && isempty(which('Model.slx'))
Since newer versions of Simulink use the .slx extension for models.
You can alternatively also use the exist function.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Modeling에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by