How to save Simulink model without model workspace saved

2 次查看(过去 30 天)
I have a Simulink model named “input_check.slx” and I want to load model parameters loaded from an external .mat file. After I run the model (out = sim(‘input_check’);), I want to save the model to the file of same name without its parameters in model workspace saved and close the system ‘input_check’. For some reason, I want the model workspace cleared when I close system so I set 'SaveModelWorkspace' = false
load_system('input_check')
hws = get_param('input_check', 'modelworkspace');
hws.DataSource = 'MAT-File';
hws.FileName = 'slx_input_check_pars.mat';
hws.reload; %reload variable from an external file to model workspace
out = sim('input_check')
save_system('input_check',[],'SaveModelWorkspace',false)
close_system('input_check')
load_system('input_check')
hws = get_param('input_check', 'modelworkspace');
After I save and close the model I load the system and get the model workspace (last two lines in code) and figure out the data source for model workspace is still there and is the .mat file I loaded earlier. I think set ‘SaveModelWorkspace’ = False should clear the model workspace but obviously not. What cause this issue? Also if I want to save the model to the file of same name without its parameters in model workspace saved, am I doing correctly?
Matlab Version is R2020a.

采纳的回答

Rishabh Mishra
Rishabh Mishra 2020-9-30
Hi,
I’m assuming you want to clear the model workspace once you close it. You can do so by:
  1. Go to model settings>model properties in the MODELLING tab in the Simulink model.
  2. In model properties go to callbacks tab, In the ‘PostLoadFcn’ section, copy the code given below.
mdlWks = get_param('input_check','ModelWorkspace');
clear(mdlWks);
Click apply and save the model.
Once you close the model & open it again the next time, the model workspace gets cleared.
For better understanding, refer the following article:
Hope this Helps.

更多回答(1 个)

Sudhakar Shinde
Sudhakar Shinde 2020-9-28
编辑:Sudhakar Shinde 2020-9-28
If you dont need any data from model workspace you could clear whole model workspace data simply by two lines.
before save you can use below:
mdlWks = get_param('input_check', 'modelworkspace');
clear(mdlWks);
save_system('input_check');

类别

Help CenterFile Exchange 中查找有关 Manage Design Data 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by