change parameter name programmatically in stateflow

9 visualizaciones (últimos 30 días)
Yunyu Hu
Yunyu Hu el 25 de Mayo de 2018
Editada: Jimmy Nguyen Hoang el 29 de En. de 2019
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

Respuesta aceptada

Jimmy Nguyen Hoang
Jimmy Nguyen Hoang el 29 de En. de 2019
Editada: Jimmy Nguyen Hoang el 29 de En. de 2019
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

Más respuestas (0)

Categorías

Más información sobre Complex Logic en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by