Trying to normalize a matrix across all element values.
40 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the triu of an 8x8 adjacency matrix A shown below. I would LIKE to normallize all the non-zero elements using normalize(A,'range'), for instance with output values between 0 and 1, but NOT column or row-wise - I'd like to normalize across ALL non-zero values. I haven't been able to find options for this. Any help appreciated!
[ 0 54 70 67 18 13 100 18
0 0 89 67 20 37 47 99
0 0 0 38 20 43 49 13
0 0 0 0 26 30 62 27
0 0 0 0 0 11 91 88
0 0 0 0 0 0 17 18
0 0 0 0 0 0 0 4
0 0 0 0 0 0 0 0 ]
0 commentaires
Réponse acceptée
dpb
le 27 Jan 2026 à 20:41
M=[ 0 54 70 67 18 13 100 18
0 0 89 67 20 37 47 99
0 0 0 38 20 43 49 13
0 0 0 0 26 30 62 27
0 0 0 0 0 11 91 88
0 0 0 0 0 0 17 18
0 0 0 0 0 0 0 4
0 0 0 0 0 0 0 0 ];
M(M~=0)=rescale(M(M~=0),0,1)
2 commentaires
Plus de réponses (1)
Matt J
le 27 Jan 2026 à 21:01
Modifié(e) : Matt J
le 27 Jan 2026 à 21:06
Normalize across only non-zero elements, or across elements only in the upper triangle? If the latter, then,
A=[ 0 54 0 67 18 13 100 18
0 0 89 67 0 37 47 99
0 0 0 38 -1 43 49 13
0 0 0 0 26 30 62 27
0 0 0 0 0 11 91 88
0 0 0 0 0 0 17 18
0 0 0 0 0 0 0 4
0 0 0 0 0 0 0 0 ];
idx=triu(true(size(A)),1);
A(idx) = normalize(A(idx),'range')
3 commentaires
dpb
le 27 Jan 2026 à 22:32
Modifié(e) : dpb
le 29 Jan 2026 à 17:01
"the zero scale then ended up zeroing out some "weights" in the adjacency matrix"
That's the solution you asked for -- "I would LIKE to normallize all the non-zero elements ...with output values between 0 and 1,"
What is supposed to be the minimum value then, if not zero? Specify it as the lower bound.
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!