How to filter a matrix?
Show older comments
I'm clustering my data with the aim to produce a force directed graph. I've got the script running but the graphs are too connected and in need of filtering. As I produce the charts from the pdist function I want to filter out all but the top 10 values per row so that each node has no more than 10 edges in the resulting graph.
[M, Idx] = max(A,[],2)
gives me the max value and the location along the row but I'm unsure how to find the top 10 positions for each row or how to convert that back into an array of the same size as A
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 15 Apr 2016
A=randi(80,4,20)
n=size(A,1)
max1=zeros(n,10);
indices=zeros(n,10);
for k=1:size(A,1)
[ii,jj]=sort(A(k,:),'descend');
max1(k,:)=ii(1:10);
indices(k,:)=jj(1:10);
end
Categories
Find more on Categorical Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!