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:(adsbygoogle = window.adsbygoogle || []).push({});

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.

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Issues with basic Matlab command

Tags:

Loading...

Similar Threads - Issues basic Matlab | Date |
---|---|

Issues Replicating Simulink Model within MATLAB (2DOF) | Mar 11, 2017 |

MATLAB sum loop issue | Feb 18, 2016 |

MATLAB plotting issue | Oct 21, 2015 |

Maxima questions and issues | Feb 11, 2015 |

Matlab basic - how to get around floating point? | Aug 30, 2014 |

**Physics Forums - The Fusion of Science and Community**