Why do I get this error 'Code generation does not support changing types through assignment' in Stateflow?
120 ビュー (過去 30 日間)
古いコメントを表示
I am implementing a logic using stateflow and I need to change the value of the input if one of the entry conditions get satisfied so as to not get caught in a loop. for example in the picture the inputs are color1 and color2 which are enums of the class Color. I am assigning color1 and color2 to temporary variables. Inside the subchart the first condition will be tested and if that is satisfied it will enter codn1 and assign the temporary variable with another value so that the condn2 can be tested. If the temporary variable is not used the input can't be assigned a value during simulation. The idea here is to assign values to a and b in the same simulation time. However I end up having this error if I initiate the inputs from MATLAB workspace:
This assignment writes a 'Color' value into a 'double' type. Code generation does not support changing types through assignment. Check preceding assignments or input type specifications for type mismatches.
State 'Codn1'
"y1"
Figure1:
![Example.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202961/Example.jpeg)
But this error doesn't occur if I initate the inputs inside the simulink file using constant blocks as shown in Figure 2.
Figure 2:
![Eample2.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202962/Eample2.jpeg)
回答 (1 件)
Raghav Singhal
2019 年 2 月 20 日
I believe you currently have the default datatype for the local variable you’ve assigned is set to double, whereas it should have been set to enum datatype as the variable you are referring to in the Stateflow Chart seems to be an enum datatype. This mismatch may be causing the aforementioned error during code generation
One way to resolve this would be to try changing the local variable type to enum <class> type within the Stateflow block. Once you explicitly change it, it should work fine.
Please refer to the following documentation link for further information:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Simulink Functions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!