Integers only

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.?

Antworten (2)

Walter Roberson
Walter Roberson am 6 Mai 2011

1 Stimme

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.
Sean de Wolski
Sean de Wolski am 6 Mai 2011

0 Stimmen

just define it as integer:
intdata = int64(double_data);

3 Kommentare

Walter Roberson
Walter Roberson am 6 Mai 2011
Note: support for arithmetic for 64 bit integers is very new in MATLAB.
Sean de Wolski
Sean de Wolski am 6 Mai 2011
Out of curiosity, what version Walter? They work for me in 2009b.
Teja Muppirala
Teja Muppirala am 7 Mai 2011
64-bit arithmetic was added in 2010b.
This will not work in 2010a or earlier:
x = int64(5)
x = 2*x

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 6 Mai 2011

Community Treasure Hunt

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

Start Hunting!

Translated by