How to Limit number of 1's in each row in matrix matlab
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I forming a connectivity matrix such that I want to limit number of 1's in each row. For eg if input size is 15, 30, 80 , 100, highest degree of connectivity should be limited such that 6 , 8, 8, 9. The condition is i) at least one 1 should be there in each row, ii) diagonal should be 0 and iii) matrix should be symmetric.I have tried this code but it doesn't limits the ones when input size became higher.
m = input('No. OF ROWS AND COLUMNS : ');
P = rand(m,m); %// generate random numbers in [0,1]
p=0.4;
result = rand(m,m)<p; %// generate matrix
result(bsxfun(@plus, floor(m*rand(1,m))*m, 1:m)) = 1;
for i=1:m
for j=1:m
result(j,i)=result(i,j);
end
end
result(logical(eye(size(result)))) = 0
A=sum(result)
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!