How I can remove n smallest values in table?

I have a table like this:
pic-table.jpg
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?

 Accepted Answer

madhan ravi
madhan ravi on 19 Jan 2019
Edited: madhan ravi on 19 Jan 2019
idx=sort(T{3,:}) % where T is your table
T(:,ismember(T{3,:},idx(1:3))) =[ ]

2 Comments

Thanks.
But the problem is that I don't want to transform my table to cell. The comments work on cell.
How I can work with table?
Those commands work for table , there was no conversion made whatsoever see https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html

Sign in to comment.

More Answers (1)

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 Comments

Thanks.
I encounter error in running the code.
But the problem is that I don't want to transform my table to cell. The comments work on cell.
How I can work with table?
{} 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?

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!