Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a binary matrix of 6x3 in which six elements (m13,m23, m33, m42, m52, m61) are constant and assigned '0' value; whereas for other twelve elements (m11, m12, m21, m22, m31,m32, m41, m43, m51, m53, m62, m63) I want to assign value of "1" with the probability of 0.5. Given below my effort, I had made yet.

mat = Table[Subscript[m, i, j], {i, 6}, {j, 3}];
mat // MatrixForm
n = Round[18*0.5];
k = RandomSample[{mat[[1, 1]], mat[[1, 2]], mat[[1, 3]], mat[[2, 1]], 
   mat[[2, 2]], mat[[2, 3]], mat[[3, 1]], mat[[3, 2]], mat[[3, 3]], 
   mat[[4, 1]], mat[[4, 2]], mat[[4, 3]], mat[[5, 1]], mat[[5, 2]], 
   mat[[5, 3]], mat[[6, 1]], mat[[6, 2]], mat[[6, 3]]}, n]
share|improve this question
1  
See SparseArray, RandomInteger, Condition and MemberQ – Dr. belisarius Jan 6 at 20:45
SparseArray[{i_, j_} :>  RandomInteger[{0, 1}] /; j != IntegerLength[7 - i, 2], 
            {6, 3}, a] // MatrixForm

Mathematica graphics

share|improve this answer
    
Kindly explain it briefly. – Mamoona Jan 6 at 21:34
    
@Mamoona Please read the docs for each function and then ask specifically about the ones you don't understand – Dr. belisarius Jan 6 at 23:48

One approach to this problem is to populate the whole matrix 0/1 with equal probabily, then set the desired elements to zero:

ReplacePart[ 
  RandomInteger[1 , {6, 3}] ,
     {{1, 3} , {2, 3} , {3, 3}, {4, 2}, {5, 2}, {6,1}} -> 0 ] // MatrixForm
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.