How to separate the integer value of a real number

For example a variable A is calculated as {2.951,5.420,8.062,4.963, .....} I want A to have just the integer values of these real numbers, i.e. A={2,5,8,4,....}

 採用された回答

Sachin Ganjare
Sachin Ganjare 2012 年 9 月 26 日
編集済み: Sachin Ganjare 2012 年 9 月 26 日

0 投票

Just use Floor function.
A_INT = floor(A);

その他の回答 (1 件)

TAB
TAB 2012 年 9 月 26 日

2 投票

A = cellfun(@(x)(fix(x)),A,'UniformOutput', false)

3 件のコメント

Jan
Jan 2012 年 9 月 26 日
Anonymous functions in CELLFUN are much slower than functions handles. Does this work:
cellfun(@fix, x,'UniformOutput', false)
TAB
TAB 2012 年 9 月 26 日
編集済み: TAB 2012 年 9 月 26 日
@Jan, Yes, it will also work.
TAB
TAB 2012 年 9 月 26 日
A= {1:0.55:1000};
TEST 1
tic
cellfun(@fix,A,'UniformOutput', false);
toc
>> Elapsed time is 0.000161 seconds.
TEST 2
tic
cellfun(@(x)(fix(x)),A,'UniformOutput', false);
toc
>> Elapsed time is 0.000442 seconds.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by