Why do I get this error 'Code generation does not support changing types through assignment' in Stateflow?
129 views (last 30 days)
Show older comments
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:
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:
1 Comment
Answers (1)
Raghav Singhal
on 20 Feb 2019
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 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!