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

1 view (last 30 days)
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.

Answers (1)

Mark McBroom
Mark McBroom on 21 May 2022
Try using Simulink.Parameter rather than Simuilnk.Signal.

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!