MATLAB: Hi every one , Is there any way to fill specific cells of a matrix with random number Not all the matrix

randi

Best Answer

It is easiest to use linear indexing for your problem.
The Code
A = zeros(3,5);
A([3 4 5 8 10 12 13 15]) = randi(9, 1, 8)
A =
0 2 0 1 2
0 5 4 0 0
6 0 0 2 7
Since the numbers are random, you will get different results. The numbers will be in the required locations in ‘A’.