How to filter a matrix?
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2016년 4월 15일
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
카테고리
도움말 센터 및 File Exchange에서 Categorical Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!