Repeated Values in matrix

2 Ansichten (letzte 30 Tage)
mustafa alnasser
mustafa alnasser am 6 Mär. 2014
Beantwortet: Azzi Abdelmalek am 6 Mär. 2014
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 Kommentar
Walter Roberson
Walter Roberson am 6 Mär. 2014
What do you want done if one of the y values is unique instead of being repeated?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Mär. 2014
[uvals, ua, uc] = unique(xy(:,1));
maxy = accumarray(uc(:), xy(:,2), [], @max);
newarray = [uvals(:), maxy(:)];

Weitere Antworten (1)

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

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by