matlab中如何实现数据分类,求一个源代码。
发布网友
发布时间:2022-10-15 04:23
我来回答
共1个回答
热心网友
时间:2023-10-03 21:31
x = [1,6,9,13,2,8,7,4,11,5,3,10,12];
GroupName = ['A','B','C','D'];
numGroups = length(GroupName); % 组的数目
xMax = max(x);
xMin = min(x);
boundries = xMin + (0:numGroups) * (xMax - xMin) / (numGroups - 1); % 组的边界
xGroup = zeros(size(x)); % 初始化
for group = 1:numGroups
loc = (x >= boundries(group)) & (x <= boundries(group + 1)); %在这个组的书的坐标
xGroup(loc) = group;
end
xGroupName = GroupName(xGroup);
for ii = 1:length(x)
fprintf('%d : %s\n', x(ii), xGroupName(ii));
end
希望能帮到你