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?

 Akzeptierte Antwort

madhan ravi
madhan ravi am 19 Jan. 2019
Bearbeitet: madhan ravi am 19 Jan. 2019

0 Stimmen

idx=sort(T{3,:}) % where T is your table
T(:,ismember(T{3,:},idx(1:3))) =[ ]

2 Kommentare

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?
madhan ravi
madhan ravi am 20 Jan. 2019
Bearbeitet: madhan ravi am 20 Jan. 2019
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 19 Jan. 2019

0 Stimmen

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

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?
Walter Roberson
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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by