필터 지우기
필터 지우기

How can I stop Stateflow from inferring double as datatype

조회 수: 4 (최근 30일)
Elon
Elon 2014년 9월 8일
편집: Sebastian Castro 2015년 5월 15일
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
Elon 2014년 9월 12일
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
Sebastian Castro
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
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.

Dave Walter
Dave Walter 2014년 9월 11일
I am having this exact same issue. Anybody have a solution?

카테고리

Help CenterFile 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!

Translated by