In Matlab, I would like to know how to assign values inside a matrix randomly for any given size matrix?
For example:
Enter non-zero elements in 3*3 matrix? 3
1
4
7
These elements are to be randomly placed in 3*3 matrix and the remaining 6 elements become zero.
In general, for some number of non-zero elements we enter in a matrix, the remaining elements in the matrix become zero.
How do I write the code in Matlab for the above example? I have to give as input the number of non-zero elements and assign the input values randomly inside the matrix without specifying any particular row or column.