I have a MATLAB project (not Simulink) that I am generating C code for to run on a NVIDIA Jetson Nano. In it, I have a persistent variable that will only be a small integer, but MATLAB coder by default sets it to a double.
To work around this, I explicitly cast the variable to be a be a uint8 using the following snippet:
When I then use the Check for Run-Time Issues step in the MATLAB Coder, it fails with the following error
This assignment writes a 'double' value into a 'uint8' type. Code generation does not support changing types through assignment. Check preceding assignments or input type specifications for type mismatches.
I scrolled down to the point where this error was reported, and found that the line in question in the following:
This is (obviously) a number that can be represented with a uint8, but MATLAB Coder seems to have decided to use it as a double. If I cast the variable again here, the error goes away. However, my project sets the variable multiple times, and there are many other variables that I would like to represent as an integer. Do I have to manually cast the variable every time that I set it, or is there a way for matlab to automatically convert the number to a uint8?