Integers only
조회 수: 10 (최근 30일)
이전 댓글 표시
I have an application in which I have to use completely integer data format. Without using floor,Ceil,fix etc for each and every variable, how can I write a single command so that entire program can perform only in integer mode.?
댓글 수: 0
답변 (2개)
Walter Roberson
2011년 5월 6일
Sean de's answer unfortunately is not sufficient for your purposes.
There is no command or setting that you can use in MATLAB to force the use of all integers. For example
K = K + 1
would interpret the 1 as a double precision number (but would convert it to integer if K is an integer data type.)
Some operations such as mean() internally convert values to double precision, as adding a number of integers is likely to produce integer overflow.
Your options are to use the Fixed Point Toolbox, or to use Embedded MATLAB.
댓글 수: 0
Sean de Wolski
2011년 5월 6일
just define it as integer:
intdata = int64(double_data);
댓글 수: 3
Teja Muppirala
2011년 5월 7일
64-bit arithmetic was added in 2010b.
This will not work in 2010a or earlier:
x = int64(5)
x = 2*x
참고 항목
카테고리
Help Center 및 File Exchange에서 Fixed-Point Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!