Avoid searching the commented out logic seach in Stateflow API.

I'm using a script to find all the parameters used in Stateflow logic of the model.
rt = sfroot;
m= rt.find('-isa','Stateflow.Chart'); % If not used in Simulink , Check in stateflow
params_sf = m.find('-isa', 'Stateflow.Data','Name',c_name);
*c_name - has the parameter name
But the only issue in this finds the parameters which are involved also in commented out statecharts.
How can i avoid searching in Commented out statecharts ??

 채택된 답변

Uday Pradhan
Uday Pradhan 2020년 12월 14일
Hi Arjun,
According to my understanding, you want ignore the charts that are commented in the Stateflow logic of your model. To do this, you can create a custom filtering function to be used along with "find". Example:
f = @(h) (strcmp(get_param(h.path,'Commented'),'off')); %for the chart, return true if it is not commented
m = rt.find('-isa','Stateflow.Chart','-and','-function',f); %only returns those charts which are uncommented
I hope this helps!

댓글 수: 7

Arjunkrishna Mitta
Arjunkrishna Mitta 2020년 12월 14일
편집: Arjunkrishna Mitta 2020년 12월 14일
I tried the above but its not working .. The variable f doesnt have any value stored after evaluation.
Hi Arjun, Please elaborate. Is it not filtering commented charts?
Sorry its my mistake its working now. I had used rt.path which was NULL ... But changing it to just rt solved the issue. Its working as expected Thank you
That's nice to hear, Arjun!
Hello Uday can you cross check the syntax. Because its also finding parameters in stateflow which are not commented as well.
rt = sfroot;
f = @(rt)(strcmp(get_param(rt,'Commented'),'off'));%for the chart, return true if it is not commented
m = rt.find('-isa','Stateflow.Chart','-and','-function',f);
params_sf = m.find('-isa', 'Stateflow.Data','Name',c_name);
I'm unable to find documentation as well for the custom filter you mentioned. even the link to documentation helps
get_param(blockName,'Commented') returns 'on' or 'off' according to if the block is commneted or not. So I used this property to check if a chart if commented or not. In its present form:
f = @(rt)(strcmp(get_param(rt,'Commented'),'off'));%for the chart, return true if it is not commented
m = rt.find('-isa','Stateflow.Chart','-and','-function',f);
Should give charts that are NOT commented. I assume that is what you originally asked for. Here are the documentation pages I followed: find (check example section) and get_param.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

릴리스

R2018b

태그

질문:

2020년 12월 11일

댓글:

2020년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by