how to check syntax error in state flow chart
12 次查看(过去 30 天)
显示 更早的评论
Hello All,
I would like to check syntax errors in state flow state chart. As you see below, I have called state which is State_name, Inside this state I have different actions. If you see state_action2 = 0 missed by following semi colon(;) and state_action3 is not within state area.
How can I check state actions line by line and syntax errors by using m-script/commands?
Any help would be appreciated..
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150540/image.png)
0 个评论
采纳的回答
Anthony Poulin
2015-5-28
I give you a small code (not optimize and without check...). The code give the "txt" variable which is the text from a stateflow state and then I put each line in a cell of the cell array "Line".
nlChar = findstr(txt, 10);
Line{1,1} = txt(1:nlChar(1));
for i = 2:length(nlChar)
Line{i,1} = txt(nlChar(i-1)+1:nlChar(i));
end
Line{i+1,1} = txt(nlChar(i):end);
Then, when you have this cell aray, you just have to make your check on each cells.
9 个评论
Anthony Poulin
2015-5-29
Hello,
First I use the function "findstr" and it is a mistake because this function will be removed so prefer "strfind" function.
Then what I suggest is to make a cell array (1 cell per text line) containing a boolean. For each line containing "=", if the last (=> last line) or penultimate character (=> other lines, because the last char must be char(10))is a ";", then you have 1 oterwise 0?
nlCharEqualArray = {};
nlChar = strfind(txt, 10);
Line{1,1} = txt(1:nlChar(1));
for i = 2:length(nlChar)
Line{i,1} = txt(nlChar(i-1)+1:nlChar(i));
end
Line{i+1,1} = txt(nlChar(i):end);
for k=2 : length(Line)
nlCharEqual = strfind(Line{k}, '=');
if (~isempty(nlCharEqual))
nlCharEqualArray{k,1} = ~isempty(strfind(Line{k}(end-1:end), ';'));
%I test on the 2 last characters, if you want to test on the 5 (for exemple), just do: Line{k}(end-5:end)
end
end
Is it clear?
更多回答(2 个)
Anthony Poulin
2015-5-27
Hello,
I can give you some command line which help you to access to the content of the stateflow chart.
% to catch the root of the stateflow chart, that yoy have selected by clicking on it
SfPath = gcb;
% to catch the stateflow object
SfObj = get_param(SfPath,'Object');
% to catch the chart object
ChartObj = SfObj.find('-isa','Stateflow.Chart');
% to catch all the StatesObj of the chart
StatesObj= ChartObj.find('-isa','Stateflow.State');
% To get the string in the FIRST chart (=> StatesObj(1))
StringInChart = get(StatesObj(1),'LabelString');
I hope it can help you.
(When I needed to access to stateflow data I found a lot of information in: Help > Stateflow > User's Guide > Using the API)
Anthony Poulin
2015-5-27
Yes, you catch a char containing all the text.
Then you have to treat this char, to separate the line you can find the character "char(10)" (= new line) or "char(13)" (= carriage return).
Is it ok for you, or do you want a short example?
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!