How can I change non zero values of a matrix into a value that increments for each element it is applied to.
2 views (last 30 days)
Show older comments
I have a matrix A filled with zero's and non zero values. I wish to change all the non zero values of A into a unique number. To do this I thought of changing the first non zero value to 1 then the next to 2.. and so on until the end of the matrix is reached. I'm new to Matlab and not sure how to go about doing this.
I'm aware that I can use
A(A!=0) = [x]
But I'm not sure how to set x up so it's a unique value each time.
Thanks.
2 Comments
See Also
Categories
Find more on Linear Algebra 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!