MATLAB Answers

How can I stop Stateflow from inferring double as datatype

4 views (last 30 days)
Elon on 8 Sep 2014
Edited: Sebastian Castro on 15 May 2015
In Matlab R2014a, when I define an output port in a Stateflow model and give it a type other than 'double', I must explicitly cast to that other type every time I assign to the output or I get the following error:
Specifically this error is for the fixed data point type 'fixdt(0,3,0)' which I cannot cast to when assigning to the output.
How do I stop Stateflow from assuming that uncast numbers are 'double'. Or, phrased differently, how can I make Stateflow inherit the data type of my output variable when I assign to it, as was the case in R2013a?

Answers (3)

Elon on 12 Sep 2014
I believe this can be fixed by changing the Action Language in Model Explorer for the top chart level to C instead of MATLAB.

  1 Comment

Sebastian Castro
Sebastian Castro on 15 May 2015
Starting with R2014a, the default action language changed from C to MATLAB, which is likely why you found this incompatibility now.
For a quick (and unnecessary) history lesson:
  • Prior to R012a: Chart block used only C
  • R2012a: "Chart" block for C, "Chart (MATLAB)" block for MATLAB
  • R2014a: Single "Chart" block, can switch action languages in options, default language is MATLAB
Indeed, C action language does not require you to explicitly cast data for assignments. Louise's answer below (to use the fi function) is how you can cast data to fixed-point representations.
However, be careful in being too quick to switch! With the MATLAB action language (as its name might suggest), you have access to all the subset of MATLAB Functions supported for code generation. With C, the mathematics support is pretty minimal -- to the point where any matrix operations, for example, would require either a for-loop or a MATLAB Function component in your chart.
So, make sure switching to C won't sacrifice any other functionality you may need later.

Sign in to comment.

Louise Forbes
Louise Forbes on 15 May 2015
Edited: Louise Forbes on 15 May 2015
If you have a variable, say myvar, with datatype that is fixdt(0,3,0) and using the MATLAB Action Language in Stateflow. Then in the Stateflow state say eg: myvar = fi(14,0,3,0) Where 14 is the value you want and the 0,3,0 are referencing the fixed point information.


Sign in to comment.

Dave Walter
Dave Walter on 11 Sep 2014
I am having this exact same issue. Anybody have a solution?


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!