How I can remove n smallest values in table?
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 19 de En. de 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 comentarios
Alireza Entezami
el 20 de En. de 2019
Walter Roberson
el 20 de En. de 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?
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!