Trying to normalize a matrix across all element values.
34 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
dpb
on 27 Jan 2026 at 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)
More Answers (1)
Matt J
on 27 Jan 2026 at 21:01
Edited: Matt J
on 27 Jan 2026 at 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 Comments
dpb
on 27 Jan 2026 at 22:32
Edited: dpb
38 minutes ago
"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.
See Also
Categories
Find more on Matrix Indexing 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!