# A compact way to reduce, or remove, the fractional part (separated by a decimal point) of numbers in a table

4 Ansichten (letzte 30 Tage)
Sim am 27 Nov. 2023
Kommentiert: Sim am 27 Nov. 2023
Given a table, could you please suggest a compact way to reduce, or remove, the fractional part (separated by a decimal point) of numbers within that table?
Note: Here following, I create a table given some inputs (i.e. Feature 1 and Feature 2) just to show an example, but in my "real" case I would have huge tables directly read from files and I would need a way/method to reduce the decimals just by manipulating the table (indeed, I would have difficulties to extract the inputs from those files, and I would need/prefer to work on the tables):
LastName = {'Paris';'London'};
Feature1 = [71.4589;69.1432];
Feature2 = [176.3458;163.9082];
T = table(Feature1,Feature2);
T.Properties.RowNames = LastName;
For example, from this:
T
T = 2×2 table
Feature1 Feature2 ________ ________ Paris 71.459 176.35 London 69.143 163.91
to this:
T =
2×2 table
Feature1 Feature2
________ ________
Paris 71 176
London 69 163
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Dyuman Joshi am 27 Nov. 2023
Take the floor of the data.
LastName = {'Paris';'London'};
Feature1 = [71.4589;69.1432];
Feature2 = [176.3458;163.9082];
T = table(Feature1,Feature2);
T.Properties.RowNames = LastName;
%Applying directly to the whole table
T1 = floor(T)
T1 = 2×2 table
Feature1 Feature2 ________ ________ Paris 71 176 London 69 163
%Applying to certain columns/variables
T2 = floor(T(:,1:2))
T2 = 2×2 table
Feature1 Feature2 ________ ________ Paris 71 176 London 69 163
##### 3 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Dyuman Joshi am 27 Nov. 2023
You're welcome!
It's a relatively new feature iirc, though I do not exactly know when it was introduced.
I'll let you know when i I get back to my PC (I am afk rn)
Yes, round() to round the data according to need.
Sim am 27 Nov. 2023
thanks a lot :-)

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by