Effacer les filtres
Effacer les filtres

change parameter name programmatically in stateflow

8 vues (au cours des 30 derniers jours)
Yunyu Hu
Yunyu Hu le 25 Mai 2018
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

Réponse acceptée

Jimmy Nguyen Hoang
Jimmy Nguyen Hoang le 29 Jan 2019
Modifié(e) : Jimmy Nguyen Hoang le 29 Jan 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

Plus de réponses (0)

Catégories

En savoir plus sur Complex Logic dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by