How can I set a Block-parameter value that is a Simulink.Signal contained in a struct?

조회 수: 1 (최근 30일)
I have a simulink model with some Blocks which some of their parameters are Simulink.signals. I want get this signals, save them in a structure in the workspace and set they again. I did following:
load_system(MODEL)
parameterNames = fieldnames(get_param(BLOCK,'DialogParameters'))
parameterValues = cellfun(@(x) get_param(BLOCK,x),parameterNames,'UniformOutput', false)
for i = 1:numel(parameterNames)
% some of the values are Simulink.signals
oldParameterValue = parameterValues(i)
% save the Simulin.signal in a struncture in workspace
newVarName = ['Structure.Signal' int2str(i)]
assignin('base',newVarName,oldParameterValue)
% set the new value
set_param(BLOCK,parameterNames{i},newVarName)
end
The previous code results in an error. I found that for Simulink.signals, the value need to be given inside ' '. Thus
set_param(BLOCK,parameterNames{i},'newVarName')
However, 'newVarName' is not my signal, therefore I changed to
set_param(BLOCK,parameterNames{i},sprintf('%s',newVarName)
Then, I become a error, that the name is not a allowed value name. I checked the error, and I found that the problem is that the new variable name has a point "Structure.Signal".
Please help me to set this new signal.

답변 (1개)

Mark McBroom
Mark McBroom 2022년 5월 21일
Try using Simulink.Parameter rather than Simuilnk.Signal.

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by