How can I stop Stateflow from inferring double as datatype
3 次查看(过去 30 天)
显示 更早的评论
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?
回答(3 个)
Elon
2014-9-12
1 个评论
Sebastian Castro
2015-5-15
编辑:Sebastian Castro
2015-5-15
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.
Louise Forbes
2015-5-15
编辑:Louise Forbes
2015-5-15
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Syntax for States and Transitions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!