- #1
Ascendant78
- 328
- 0
I need to figure out how to create a matrix that has zeros in everything except the diagonal, and I need the diagonal to be random numbers from 1 to 5. I tried a few different variations like this:
R = eye(5)*7*randi(10,5)
But I keep ending up with values in every row and column and I am at a loss as to why. I would think that multiplying the random by the identity matrix would clear out everything but the diagonal, but this code doesn't seem to be the right way to go about doing that. If anyone can help me out, I'd appreciate it.
R = eye(5)*7*randi(10,5)
But I keep ending up with values in every row and column and I am at a loss as to why. I would think that multiplying the random by the identity matrix would clear out everything but the diagonal, but this code doesn't seem to be the right way to go about doing that. If anyone can help me out, I'd appreciate it.