I have a zero-one matrix in MATLAB as follows:
[0 0 0 1 1 1
0 1 1 0 0 0
1 0 0 0 0 1
1 1 1 0 0 0
0 0 0 1 0 1]
I want to define another matrix including rand values instead of indexes of above matrix by 1
. For instance the desired new rand matrix should be:
[0 0 0 0.2 0.2 0.1
0 0.6 0.7 0 0 0
0.4 0 0 0 0 0.6
0.7 0.8 0.5 0 0 0
0 0 0 0.3 0 0.4]
I used a two nested loop for
to find non-zero values from first matrix and replace the rand values instead of them in a new matrix.
Is there any function of matlab to do it automatically, without using two nested loop for
?