Matlab中重叠的要素值值 [英] overlapping feature values values in matlab

查看:79
本文介绍了Matlab中重叠的要素值值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有矩阵

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.

我必须删除第1,3,4和5行,因为对于第一列,第四列有2个不同的值,对于第三列(39和39),相同的是再次作为类标签被改变了. 所以输出应该像

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];

推荐答案

直接的方法是遍历各列,为每个值计算不同类的数量,并删除与多个类相关的值的行.

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.

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

结果是:

F =
    28    31    19     1

这篇关于Matlab中重叠的要素值值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆