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

1 visualización (últimos 30 días)
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.

Respuestas (1)

Mark McBroom
Mark McBroom el 21 de Mayo de 2022
Try using Simulink.Parameter rather than Simuilnk.Signal.

Categorías

Más información sobre Event Functions en Help Center y File Exchange.

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