Suppose I have a matrix M 500x500
and I want to find first 100 index that have the most value in M
my idea was sort the data M in descending order and use find to compare
[x,y] = find(M == sort(M(:),'descend'), 100, 'first');
But when I run the program I found error
I think it probably M == sort(M(:),'descend')
this part
Can you help me please?
You don't need find
. Just use the second output of sort
:
[~, iSorted] = sort(M(:),'descend');
[x y] = ind2sub(size(M), iSorted(1:100));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.