How to set Simulink block parameters using an absolute model path
조회 수: 11 (최근 30일)
이전 댓글 표시
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:\Users\MATLAB\myModel.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:\Users\MATLAB\myModel.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:Users\MATLAB\myMdl.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?
댓글 수: 2
Oliver Jaehrig
2025년 1월 30일
편집: Oliver Jaehrig
2025년 1월 30일
Why are you trying to do this at all (I mean using the absolute path)?
The model in memory which can be referenced by using the name of the file (in your case myMdl) can be used with set_param and get_param as you already mentioned, so it should not be needed to do this.
Also:
"the handel "h" could not be used in the set_param function."
the handle should work. What error message do you get? Could it be that the issue is, that you are trying to concatenate the handle with a block path?
채택된 답변
Fangjun Jiang
2025년 1월 30일
편집: Fangjun Jiang
2025년 1월 30일
The "absolute model path" of a block starts with the name of the model, not including the file folder where the model file is stored.
so typically,
open_system("C:\Users\MATLAB\myModel.slx")
get_param("myModel\myConstBlk",'Value')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!