change parameter name programmatically in stateflow

8 次查看(过去 30 天)
Hello, I want to change all the parameter names in stateflow with some script. with the following script I can see the change of parameter name in model explorer:
ChartObj=sfrt.find('-isa','Simulink.BlockDiagram','-and','Name',gcs);
stateChart = ChartObj.find('-isa','Stateflow.Chart');
objArray = stateChart.find('-isa','Stateflow.Data','Scope','Parameter');
set(objArray(i),'Name',new_label);
But the entry in the stateflow still uses the old label name. So when I do ctrl+D, there is error. Can you tell me how to change the entry also with the script? Thanks

采纳的回答

Jimmy Nguyen Hoang
Jimmy Nguyen Hoang 2019-1-29
编辑:Jimmy Nguyen Hoang 2019-1-29
function SF_RenameParam(ChartName,ParaOldname,ParaNewname)
rt = sfroot;
m = rt.find('-isa','Simulink.BlockDiagram');
%ch = m.find('-isa','Stateflow.Chart');
ch = m.find('-isa','Stateflow.Chart','Name',ChartName);
%Rename Parameter in workspace
chData = ch.find('-isa', 'Stateflow.Data','-and','Name',ParaOldname);
chData.Name = ParaNewname;
%Rename Parameter name in stateflow transition label
ch_transitions = ch.find('-isa','Stateflow.Transition');
for index=1:length(ch_transitions)
LabelStr = ch_transitions(index).LabelString;
if ismember(ParaOldname,LabelStr)
ch_transitions(index).LabelString = strrep(LabelStr,ParaOldname,ParaNewname);
end
end
end
I hope it's helpful for you (can add find in state),
But sometime it not true for this case: in chart both have ABC and ABC1.
You can modify it follow your ideal

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Complex Logic 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by