Borrar filtros
Borrar filtros

How can I stop Stateflow from inferring double as datatype

4 visualizaciones (últimos 30 días)
Elon
Elon el 8 de Sept. de 2014
Editada: Sebastian Castro el 15 de Mayo de 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?

Respuestas (3)

Elon
Elon el 12 de Sept. de 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 comentario
Sebastian Castro
Sebastian Castro el 15 de Mayo de 2015
Editada: Sebastian Castro el 15 de Mayo de 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.

Iniciar sesión para comentar.


Louise Forbes
Louise Forbes el 15 de Mayo de 2015
Editada: Louise Forbes el 15 de Mayo de 2015
Hi
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.

Dave Walter
Dave Walter el 11 de Sept. de 2014
I am having this exact same issue. Anybody have a solution?

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by