0

In Rhapsody - after creating a class, one can create many similar objects (instances) of that class.

In matlab's stateflow tool - one can create a state which is, as far as I know, an object.

Is there a possibility to use a state in matlab's stateflow tool as a class and create one or more objects of it?

Dana
  • 1
  • 2

3 Answers3

2

I don't know if this is what you were asking, but yes you can create objects from stateflow classes.

As far as I know stateflow has many classes. For example, a stateflow state, a stateflow junction, stateflow function.

When you click to create a new state you are creating a new object of the state class. To do it programmatically you have to first get the handle of an stateflow object (this can be a whole stateflow chart or a stateflow chart for example).

To get this handle you can use the sfgco function - this function gets the handle of a stateflow object that is currently selected (in case none is selected, you get the handle to the stateflow chart object).

To create a new object of a class that has as parent a stateflow object that you have the handle you can use something like this:

Creating a new Stateflow state:

state = sfgco;
newState = Stateflow.State(state); %this creates a state inside the stateflow object selected by sfgco.

For more information look for the Stateflow API pdf file.

DVK
  • 2,726
  • 1
  • 17
  • 20
Bruno Camba
  • 117
  • 6
0

A Stateflow State is not an object. When generating code from Stateflow Charts, States are usually represented as a single "case" within a "switch" statement. They do not have properties or methods and can neither be instantiated.

Actually I am not aware that it is possible to create classes in Stateflow or Simulink at all. Both tools are intended to graphically represent algorithms and not classes, relationships or other (abstract) objects.

walderich
  • 500
  • 1
  • 9
  • 24
0

Stateflow charts are often used within Simulink, and reside inside an S-function (a block inside Simulink with time dependent inputs/outputs). Each S-function will then be an instantiation of the statechart. Normally these form a simulink model, with blocks connected by lines. Although I think it is also possible to do this dynamically, this would be far outside of the comfort region of the tools intended usage.

I've decoupled simulink (and stateflow blocks) from simulink models by using libraries. I can instantiate many of them (graphically) and update them separately from the models in which they

Adriaan
  • 3,282
  • 1
  • 23
  • 31