Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
122 views
in Technique[技术] by (71.8m points)

overlapping feature values values in matlab

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

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...