How to set Simulink block parameters using an absolute model path
I am calling a simulink model out of a MATLAB script, but this model is located in a different directory (not in the working directory).
This model can be executed by using the "sim" command in combination with the absolute path, e.g:
sim("C:UsersMATLABmyModel.slx")
Now I want to change the parameter of a "Contant" block when calling the simulation.
The functions "set_param" seems only to work with a model handle which was created by a model being in the current working path.
% name of model
mdl = "myMdl";
% name of the block
blk = "myConstBlk";
% Serch path
path = strcat(mdl, "/", blk);
% set parameter of Const
set_param(path, "Value", "5");
When performing the same action, but with an absolute path, this is not working anymore.
% name of model
mdl = "C:UsersMATLABmyModel.slx";
% name of the block
blk = "myConstBlk";
% Serch path
path = strcat(mdl, "/", blk);
% set parameter of Const
set_param(path, "Value", "5");
Invalid Simulink object name: ‘C:UsersMATLABmyMdl.slx/myConstBlk’.
Even if the model is loaded by:
h = load_system(mdl); %mdl is the absolute path
the handel "h" could not be used in the set_param function.
So therefore the qustion:
How to perform all the task provided by "set_param" and "get_param" using a model which shall be referenced by an absolute path?I am calling a simulink model out of a MATLAB script, but this model is located in a different directory (not in the working directory).
This model can be executed by using the "sim" command in combination with the absolute path, e.g:
sim("C:UsersMATLABmyModel.slx")
Now I want to change the parameter of a "Contant" block when calling the simulation.
The functions "set_param" seems only to work with a model handle which was created by a model being in the current working path.
% name of model
mdl = "myMdl";
% name of the block
blk = "myConstBlk";
% Serch path
path = strcat(mdl, "/", blk);
% set parameter of Const
set_param(path, "Value", "5");
When performing the same action, but with an absolute path, this is not working anymore.
% name of model
mdl = "C:UsersMATLABmyModel.slx";
% name of the block
blk = "myConstBlk";
% Serch path
path = strcat(mdl, "/", blk);
% set parameter of Const
set_param(path, "Value", "5");
Invalid Simulink object name: ‘C:UsersMATLABmyMdl.slx/myConstBlk’.
Even if the model is loaded by:
h = load_system(mdl); %mdl is the absolute path
the handel "h" could not be used in the set_param function.
So therefore the qustion:
How to perform all the task provided by "set_param" and "get_param" using a model which shall be referenced by an absolute path? I am calling a simulink model out of a MATLAB script, but this model is located in a different directory (not in the working directory).
This model can be executed by using the "sim" command in combination with the absolute path, e.g:
sim("C:UsersMATLABmyModel.slx")
Now I want to change the parameter of a "Contant" block when calling the simulation.
The functions "set_param" seems only to work with a model handle which was created by a model being in the current working path.
% name of model
mdl = "myMdl";
% name of the block
blk = "myConstBlk";
% Serch path
path = strcat(mdl, "/", blk);
% set parameter of Const
set_param(path, "Value", "5");
When performing the same action, but with an absolute path, this is not working anymore.
% name of model
mdl = "C:UsersMATLABmyModel.slx";
% name of the block
blk = "myConstBlk";
% Serch path
path = strcat(mdl, "/", blk);
% set parameter of Const
set_param(path, "Value", "5");
Invalid Simulink object name: ‘C:UsersMATLABmyMdl.slx/myConstBlk’.
Even if the model is loaded by:
h = load_system(mdl); %mdl is the absolute path
the handel "h" could not be used in the set_param function.
So therefore the qustion:
How to perform all the task provided by "set_param" and "get_param" using a model which shall be referenced by an absolute path? absolute path, simulink, set block parameter MATLAB Answers — New Questions