1

AS the title say. For example, imagine M = 2 and N = 2, I would like to have

0 0

0 0

SPACE

0 0

0 1

SPACE

0 0
1 0

SPACE

0 0
1 1

SPACE

0 1
0 0

SPACE

0 1
0 1

SPACE

0 1
1 1

SPACE

etc...

Every time I obtain one of the said matrix, I would need to do a check on it.

Cher
  • 163

2 Answers2

3

As each of the $MN$ entries can be either $0$ or $1$ there are $2^{MN}$ such.

to enumerate them: Write the integers $\{0,\cdots,2^{MN}-1\}$ in base $2$ (adding zeroes to to left as needed to get $MN$ entries). Then for each such, partition them into $N$ groups of $M$ those are your rows (or columns, as the case may be).

For example, consider $5\times 3$ matrices. We choose $i=167$, just to pick one. We easily get $167=10100111_2$ which we write as $000\, 000\, 010\,100\,111$. Then your rows are $\{0,0,0\}, \{0,0,0\},\{0,1,0\},\{1,0,0\},\{1,1,1\}$ so: $$\begin{bmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \\ 1 & 1 & 1 \\ \end{bmatrix} $$

lulu
  • 70,402
  • thx for your answer! Could you add the code I will paste? It took me time to do it so I feel like if someone wants it it would be nice to have the code : max = 20; padding = numel(num2str(dec2bin(max)));

    padding=strcat('%0',num2str(padding),'s'); for a = 0:max virginMatrix = zeros(O,P);

    prematrix = num2str(dec2bin(a));
    prematrix = sprintf(padding, prematrix);
    
    loopLimit = O;
    for i = 1:loopLimit
        positionToPick = 1+ (i - 1)*P;
        virginMatrix(i,:) = str2num(strjoin(num2cell(prematrix([positionToPick : (positionToPick + P - 1)]))));
    end
    

    end

    – Cher Sep 24 '16 at 18:30
  • No problem. You can post a solution to your own problem...I'd include the code there. – lulu Sep 24 '16 at 19:02
  • didn't know I could edityour post lol... added it to your answer for more simplicity – Cher Sep 24 '16 at 19:29
  • You need the author's permission to edit. If you don't mind, I'd prefer that you kept your own solution up. It is your work, after all, not mine. Also, I didn't try to run your code and wouldn't want to field questions about it from others. Third reason: I upvoted your code! Don't waste those points! – lulu Sep 24 '16 at 19:32
  • sure, I undeleted my answr – Cher Sep 24 '16 at 19:32
1

My code corresponding to accepted answer solution.

max = 5;
padding = numel(num2str(dec2bin(max)));

padding=strcat('%0',num2str(padding),'s');

for a = 0:max
    virginMatrix = zeros(O,P);

    prematrix = num2str(dec2bin(a));
    prematrix = sprintf(padding, prematrix);

    loopLimit = O;
    for i = 1:loopLimit
        positionToPick = 1+ (i - 1)*P;
        virginMatrix(i,:) = str2num(strjoin(num2cell(prematrix([positionToPick : (positionToPick + P - 1)]))));
    end
end

end
Cher
  • 163
  • (+1) for the code. I notice it didn't cut and paste properly. (text cuts off on the side). I can edit it from your earlier comment or perhaps you'd like to do it yourself? – lulu Sep 24 '16 at 19:14