change parameter name programmatically in stateflow

조회 수: 5 (최근 30일)
Yunyu Hu
Yunyu Hu 2018년 5월 25일
편집: Jimmy Nguyen Hoang 2019년 1월 29일
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에서 Stateflow에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by