Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

If I have a matrix

F=[ 24 3  17 1;
    28 31 19 1;
    24 13 25 2;
    47 43 39 1;
    56 41 39 2];

in the first three columns I have feature values a forth column is for class labels. my problem is to get rid of same feature values when class label is different for that particular values.

like for F matrix I have to remove the rows 1,3,4 and 5 ,because for first column there are 2 different values in column four and same is for third column (39 and 39)as class label again got changed. so output should look like

F=[28 31 19 1];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
120 views
Welcome To Ask or Share your Answers For Others

1 Answer

The straightforward approach would be iterating over the columns, counting the number of different classes for each value, and removing the rows for values associated to more than one class.

Example

F = [24 3 17 1; 28 31 19 1; 24 13 25 2; 47 43 39 1; 56 41 39 2];

%// Iterate over columns
for col = 1:size(F, 2) - 1

   %// Count number of different classes for each value
   [vals, k, idx] = unique(F(:, col));
   count = arrayfun(@(x)length(unique(F(F(:, col) == x, end))), vals);

   %// Remove values associated to more than one class
   F(count(idx) > 1, :) = [];
end

This results in:

F =
    28    31    19     1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...