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.
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Event Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!