Round to shortest integer

In my program I access the data using a variable. This variable is calculated from lot of stuff. Now my problem is I am getting that variable value as 1.4464e+016(14464000000000000) and data is having only 32768 elements. Now i need to round this value to shortest integer to access the data.
You can assume this program like accessing array of elements using index, my question is how can I round this index value to the shortest integer using matlab functions.

回答 (1 件)

Matt Fig
Matt Fig 2011 年 6 月 14 日

0 投票

x = 14464000000000000; % An initial value
x = min(x,32768) % Limit the value to 32768
I am not clear on what you mean by, "the shortest integer," but this will work with arrays too.
x = [200 50 0 7e20 2e14 44 10e10] % Initial values.
x = min(x,32768) % Limit the value to 32768

カテゴリ

ヘルプ センター および File ExchangeSparse Matrices についてさらに検索

タグ

質問済み:

2011 年 6 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by