Repeated Values in matrix

3 次查看(过去 30 天)
Dear All;
I have an array of two columns, I want to find each repeated values of y for each x value and then the max of these y value to this x value and make new matrix in which for each x value there is a unique y value
how to do that ?
  1 个评论
Walter Roberson
Walter Roberson 2014-3-6
What do you want done if one of the y values is unique instead of being repeated?

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2014-3-6
[uvals, ua, uc] = unique(xy(:,1));
maxy = accumarray(uc(:), xy(:,2), [], @max);
newarray = [uvals(:), maxy(:)];

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2014-3-6
v=[1 2;1 3;4 5;4 20;10 30]
[ii,jj,kk]=unique(v(:,1))
out=[ii accumarray(kk,v(:,2),[],@max)]

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by