How to force whole m file calculation in class smaller than double (e.g:uint16)

조회 수: 2 (최근 30일)
Hi all,
I`m implementing Matlab code in MCU(EFM32) by using Matlab Coder app and code replacement for ARM cortex M3. Since this micro controller has just 32K RAM, I have to use uint16 variable which is enough for me rather than double(Matlab default). I know by using uint16() I can change the class, but the think is that I do not want to manipulate the Matlab code and also because some functions call other functions,it is better to just force all calculation in other class just once. Does anybody has experience in this regard. Thanks.
  댓글 수: 1
John D'Errico
John D'Errico 2017년 10월 3일
Sorry, but you can't do it. You cannot force a complete block of MATLAB code to operate in uint16, merely by setting a flag.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 10월 3일
In a situation such as that, it is probably best to use the Fixed Point Toolbox. Even if you use it only with a built-in uint16 data type, you would be pushing your values out of the normal numeric classes, ensuring that they are not accidentally treated as belonging to some other data class. You will probably find that you want to configure the behavior on overflow (values that would exceed 65535) and underflow (values that would be negative): the MATLAB behaviors are not the ones typically implemented in hardware, so you will want to either conform to hardware or have MATLAB arrange to add extra instructions to maintain its saturation behavior.
Be especially careful about division: there are several different rounding behaviors to take into account, and sometimes you want different behavior for different calculations.
  댓글 수: 2
Ehsan Ghaheri
Ehsan Ghaheri 2017년 10월 4일
Hi Walter, I`m using m file with pure matrix operation which always needs just unsigned integers(the elements just change their position in the matrix).I think in this case use of fix point toolbox cannot help. Thanks.
Walter Roberson
Walter Roberson 2017년 10월 4일
Be careful with your index operations: unless you write them carefully it is likely you will accidentally use double at some point.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by