MATLAB: How to place a number (1) in a random position in Line 1 in a matrix of zeros

columnhelplineMATLAB and Simulink Student Suitematrixrandrandirandomrandom columnrandom placementrandom rowrowvariablevery urgent

I have a Matrix M of zeros (10,10) and I would like to know how to place randomly a variable with the value of 1 into a random spot of the Matrix but ONLY in LINE 1 of the matrix M. How would i code this for M=zeros(10,10); ?
I guess randi and numel(M) would be a good idea but i have no idea of the code.
I would really appreciate an answer and would be really thankful!
Thank you!

Best Answer

Try this:
M = zeros(10, 10);
yourVariable = 1;
column = randi(size(M, 2))
M(1, column) = yourVariable % Stuff the variable into the random column of row 1.