How can I save status of simulink model (timer, counter, state runing, . . ) and export to use after changing model

5 visualizaciones (últimos 30 días)
galaxy
galaxy el 23 de Oct. de 2024 a las 6:19
Respondida: Rahul el 23 de Oct. de 2024 a las 12:59
Hi all,
I am have a system which contains many subsystem.
It can be update when flag triger turn on.
But I want to keep status before update to using when after update.
It same case you need to update version software os, but all your configues are keeped.
So, how to using it in matlab/simulink??
  2 comentarios
Rahul
Rahul el 23 de Oct. de 2024 a las 6:48
Hi @galaxy, can you share your simulink model, and describe more on what does 'update', 'status' and 'flag trigger' refer to in your case.
Sahas
Sahas el 23 de Oct. de 2024 a las 8:54
Hi,
Assuming you need to preserve the configrurations of your Simulink model before updating your model, you can save the current state of the model and all the subsystems by exporting parameters to a .mat file.
Use MATLAB's "get_param" and "save" functions for this purpose:
currentConfigurations = get_param('your_model_name/subsystem_name', 'ObjectParameters');
save('backupConfigurations.mat', 'currentConfigurations');
After updating the model, you can use MATLAB's "load" and "set_param" functions to apply it back to that subsystem:
load('backupConfigurations.mat');
set_param('your_model_name/subsystem_name', currentConfigurations);
Refer to the following MathWorks documentation links for more information on the abovementioned functions:

Iniciar sesión para comentar.

Respuestas (1)

Rahul
Rahul el 23 de Oct. de 2024 a las 12:59
Hi galaxy,
Assuming that you are trying to extract and save model config parameters of a Simulink model containing many subsystems and want to later import and use the same configuration parameters.
In Simulink, saving and loading the configuration (parameters, states, or settings) of a model can be done if you want to preserve your configuration before updating the model.Here is a possible solution to the issue:
A Configuration Set object stores a set of model configuration parameter values such as solver type, step size, etc. You can specify a ‘Simulink.ConfigSet’ object as an input to the ‘sim’ function. The configuration set from the object is applied to the model for the simulation. After simulation, the original configuration set is restored in the model.
% Get the active configuration set of the model
configSet = getActiveConfigSet('myModel');
% Save the configuration set to a MAT file
save('myModel_configSet.mat', 'configSet');
% Load the saved configuration set from the MAT file
loadedConfig = load('myModel_configSet.mat', 'configSet');
% Apply the loaded configuration set to the model
attachConfigSet('myModel', loadedConfig.configSet, true);
Saving and Loading Simulink Block Parameter Values: You can programmatically get and set block parameters by creating a .mat file to preserve the current state of your subsystems, which allows you to save and load block configurations later.
% Get the block parameters
blockParams = get_param('myModel/Controller', 'DialogParameters');
% Save specific parameter values (e.g., gain values) to a file
Kp = get_param('myModel/Controller', 'Kp');
save('controller_params.mat', 'Kp');
% Load the saved parameters from the file
params = load('controller_params.mat');
% Apply the parameter to the block
set_param('myModel/Controller', 'Kp', num2str(params.Kp));
For more information regarding usage of functions mentioned above, refer to the following documentation links:
Hope it Helps!

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by