How I can remove n smallest values in table?
Ältere Kommentare anzeigen
I have a table like this:

I want to know that how I can remove the first, second and third smallest number from feature 3 (i.e. 3,3,6 in this example). I want to remove columns of these numbers from the table.
How can do it in matlab?
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 19 Jan. 2019
NumSmallest = 3;
[~, idx] = mink(YourTable{3,2:end}, NumSmallest);
YourTable(:,idx+1) = [];
This presumes that the Feature1 Feature2 Feature3 are an actual column in the table, rather than being RowNames. If they are RowNames then
NumSmallest = 3;
[~, idx] = mink(YourTable{'Feature3',:}, NumSmallest);
YourTable(:,idx) = [];
You do not need to use a variable for NumSmallest: I used one here to clarify which 3 was the number of smallest to consider, and which 3 was the row number.
2 Kommentare
Alireza Entezami
am 20 Jan. 2019
Walter Roberson
am 20 Jan. 2019
{} indexing is used for table() objects to access the items stored in the rows.
YourTable{3,2:end} would be a problem if not all of the columns starting from column 2 are numeric.
What error message are you getting?
Kategorien
Mehr zu Tables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!