Info

此问题已关闭。 请重新打开它进行编辑或回答。

Indices of highest values in a vector when values are repeated

1 次查看(过去 30 天)
Hi,
I have used the following code to find the top 50% highest values in vector A:
top = round(0.5*length(A))
c = flipud(unique(sort(A)))
result = c(1:top)
index=find(node_degree>=c(top))
result_at=flipud(sortrows([A(index) index], 1))
The issue that I have is some of the values are equal in A. If I have a situation where e.g.:
A = [ 20; 19; 18; 17; 17; 17; 2; 2; 2; 2]
The current code would return indices [1:5], what I would like it to do is expand its selection to return [1:6], i.e. return indices for all values that are in an equal position.
Many thanks for any assistance,
Rob

回答(1 个)

rob
rob 2017-7-13
I was able to find a solution with assistance form a comment posted elsewhere:
thresh = 0.5
B = sort(A,1,'descend')
D = B(1:find(B==B(round(length(B)*thresh)),1, 'last'))
cut_off = min(D)
index=find(A>=cut_off)
result_at=flipud(sortrows([A(index) index], 1))

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by