Clear Filters
Clear Filters

Create model only if it doesn't exist

7 views (last 30 days)
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 Comment
Chiara
Chiara on 15 May 2013
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!

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 15 May 2013
Edited: Azzi Abdelmalek on 15 May 2013
if isempty(which('Model.mdl'))
new=new_system('Model')
end
open_system('Model')
  2 Comments
Chiara
Chiara on 15 May 2013
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 on 15 May 2013
Edited: Kaustubha Govind on 15 May 2013
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!