Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, as you can see, you have several combinations of a zero matrix you want to add a one, right?</p> <p>We could say that you have the following possible combinations you want to add a one. For the 2 dimensional case:</p> <pre><code>addOnes = Empty matrix: 1-by-0 onePossibleCombination = 0 0 0 0 addOnes = 1 onePossibleCombination = 1 0 0 0 addOnes = 2 onePossibleCombination = 0 0 1 0 addOnes = 3 onePossibleCombination = 0 1 0 0 addOnes = 4 onePossibleCombination = 0 0 0 1 addOnes = 1 2 onePossibleCombination = 1 0 1 0 addOnes = 1 3 onePossibleCombination = 1 1 0 0 addOnes = 1 4 onePossibleCombination = 1 0 0 1 addOnes = 2 3 onePossibleCombination = 0 1 1 0 addOnes = 2 4 onePossibleCombination = 0 0 1 1 addOnes = 3 4 onePossibleCombination = 0 1 0 1 addOnes = 1 2 3 onePossibleCombination = 1 1 1 0 addOnes = 1 2 4 onePossibleCombination = 1 0 1 1 addOnes = 1 3 4 onePossibleCombination = 1 1 0 1 addOnes = 2 3 4 onePossibleCombination = 0 1 1 1 addOnes = 1 2 3 4 onePossibleCombination = 1 1 1 1 </code></pre> <p>How can we achieve that? All we need is to take all combinations taken by 0, 1, 2, 3 and 4. For that we use the <code>nchoosek</code> method as follows:</p> <pre><code>matrixSize = 2; for k=0:matrixSize^2 combinations=nchoosek(1:matrixSize^2,k); for m = 1:size(combinations,1) addOnes = combinations(m,:); onePossibleCombination = zeros(matrixSize,matrixSize); onePossibleCombination(addOnes) = 1; % Do your operation here with the matrix onePossibleCombination end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload