How to recognize Stateflow blocks using Simulink API (get_param)?

77 visualizaciones (últimos 30 días)
In older Matlab/simulink version it was possible to detect a Stateflow block using Simulink get_param(...) command for example for a SF block:
>> get_param(gcb, 'BlockType')
ans =
SubSystem
>> get_param(gcb, 'MaskType')
ans =
Stateflow
So a Stateflow block could be detected by queering the BlockType = 'SubSystem' and MaskType = 'Stateflow'. But since the introduction of the new Simulink Editor (R2012b) the 'MaskType' parameter for s Stateflow block is empty (''). How can I recognize SF blocks using Simulink API get_param(...) command?
Thanks.
Regards, Wojtek

Respuesta aceptada

Sebastian Castro
Sebastian Castro el 2 de Oct. de 2014
Hi Wojciech,
The most straightforward way to find Stateflow Chart blocks is by using the Stateflow API. For example, the following set of commands will give you all the Chart blocks in all currently open models.
S = sfroot;
charts = S.find('-isa','Stateflow.Chart');
To search only in some particular model:
S = sfroot;
myModel = S.find('-isa','Simulink.BlockDiagram','-and','Name','model_name');
charts = myModel.find('-isa','Stateflow.Chart');
Here is the landing page in our documentation for the Stateflow API.
  3 comentarios
Teresa Hubscher-Younger
Teresa Hubscher-Younger el 13 de Abr. de 2023
@Wojciech Przystas, I was curious about the reason being performance. Is it that you personally are faster writing APIs in Simulink or have you observed some performance issue with the Stateflow API. I realize your comment here is really old, have you tried Stateflow API recently and still think it's true?
Over the years, we have continued to work on the Stateflow API that Sebastian suggested.
-Teresa
Wojciech Przystas
Wojciech Przystas el 24 de Abr. de 2023
Thanks for your message.
In our solution, we currently use both Simulink and the Stateflow API to create our target specific configuration files.
Since this is done in the configuration phase and not in the run-time phase, it is not time critical and performance is not an issue.
Thanks.

Iniciar sesión para comentar.

Más respuestas (3)

John Harris
John Harris el 14 de Dic. de 2017
To expand on Wojtek's solution and hopefully help out others who may be looking for this answer, SFBlockType is a parameter that seems to be present on SubSystems at least as far back as R2013a.
Values for 'SFBlockType' that I have found are:
  • 'Chart' (stateflow charts)
  • 'MATLAB Function' (MATLAB Functions)
  • 'NONE' (plain subsystems)
Note non sub-system blocks don't have this parameter, so if a non-subsystem block is selected
get_param(gcb,'SFBlockType')
returns an error. Consider using a strcmp as a safety catch,
isAChart = strcmp(get_param(gcb,'SFBlockType'),'Chart');
Cheers!
  2 comentarios
Oleg Makosiy
Oleg Makosiy el 21 de Nov. de 2018
I wish i knew this years ago! thanks
Sanjeev Kumar
Sanjeev Kumar el 28 de Abr. de 2022
Thats great John!! Now I got the charts from our model. I want to set it's parameter like "Action Language" to C by set_param command but it doesn't recognize these parameters. Kindly help on it.

Iniciar sesión para comentar.


Robert
Robert el 11 de Jul. de 2017
Editada: Robert el 12 de Jul. de 2017
Sebastian already pointed out the most stable - if awkward - way, using the stateflow api search methods, though you have to be careful to search the library if a stateflow block resides there and is only linked into your system.
There is another way only using the simulink api, as you required. Using find_system(gcb ,'MaskType', 'Stateflow') still finds the block, even though get_param will yield an empty MaskType on the very same. Seems to be some kind of backwards compatibility programmed into find_system, that is still working up to 2016b. Also awkward, but pure Simulink-API.
As Embedded Matlab blocks are technically integrated as Stateflow blocks into Simulink, these will be matched by find_system(... 'Stateflow') as well. So if you need to distinguish the different kinds of Stateflow embedments into Simulink, there is no way around Stateflow API.

Jamie Wardlaw
Jamie Wardlaw el 3 de Oct. de 2018
So some years on I came back to this, the solution in 2018b that I am using is
%find stateflow charts
sf_charts = find_system(sysName,'MaskType','Stateflow');
Seems to work well.

Categorías

Más información sobre Syntax for States and Transitions en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by