How to separate the integer value of a real number

5 vues (au cours des 30 derniers jours)
University
University le 26 Sep 2012
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,....}

Réponse acceptée

Sachin Ganjare
Sachin Ganjare le 26 Sep 2012
Modifié(e) : Sachin Ganjare le 26 Sep 2012
Just use Floor function.
A_INT = floor(A);

Plus de réponses (1)

TAB
TAB le 26 Sep 2012
A = cellfun(@(x)(fix(x)),A,'UniformOutput', false)
  3 commentaires
TAB
TAB le 26 Sep 2012
Modifié(e) : TAB le 26 Sep 2012
@Jan, Yes, it will also work.
TAB
TAB le 26 Sep 2012
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by