title: Calculate rank of binary matrix with larger size
body: <p>Hell all, I have some problem when compute the rank of binary matrix that only 1 or 0. The rank of binary matrix will based on the row reduction using boolean operations XOR. Let see the XOR operation:</p>
  
  <pre><code>1 xor 1 =0
  1 xor 0= 1 
  0 xor 0= 0
  0 xor 1= 1
  </code></pre>
  
  <p>Given a binary matrix as </p>
  
  <pre><code>A =
  
       1     1     0     0     0     0
       1     0     0     0     0     1
       0     1     0     0     0     1
  </code></pre>
  
  <p>We can see the third row equals first row xor with second row. Hence, the rank of matrix A only 2, instead of 3 by rank matlab function.
  I have one way to compute the extractly rank of binary matrix using this code</p>
  
  <pre><code>B=gf(A)
  rank(B)
  </code></pre>
  
  <p>It will return 2. However, when I compute with large size of matrix, for example 400 by 400. It does not return the rank (never stop). Could you suggest to me the good way to find rank of binary matrix for large size? Thank all 
  UPDATE: this is computation time using tic toc </p>
  
  <pre><code>N=50; Elapsed time is=0.646823 seconds
  N=100;Elapsed time is 3.123573 seconds.
  N=150;Elapsed time is 7.438541 seconds.
  N=200;Elapsed time is 11.349964 seconds.
  N=400;Elapsed time is 66.815286 seconds.
  </code></pre>
  
  <p>Note that check rank is only the condition in my algorithm. However, it take very long long time, then it will affect to my method
  Base on the suggestion of R. I will use Gaussian Elimination to find the rank. This is my code. However, it call the rank function (spend some computation times). Could you modify help me without using rank function?</p>
  
  <pre><code>function rankA=GaussEliRank(A)  
      mat = A;
      [m n] = size(A);              % read the size of the original matrix A
      for i = 1 : n
          j = find(mat(i:m, i), 1); % finds the FIRST 1 in i-th column starting at i
          if isempty(j)
                  mat = mat( sum(mat,2)&gt;0 ,:);
                  rankA=rank(mat);  %%Here
                  return;
          else
              j = j + i - 1;       % we need to add i-1 since j starts at i
              temp = mat(j, :); % swap rows
              mat(j, :) = mat(i, :);
              mat(i, :) = temp;
              % add i-th row to all rows that contain 1 in i-th column
              % starting at j+1 - remember up to j are zeros
              for k = find(mat( (j+1):m, i ))' 
                  mat(j + k, :) = bitxor(mat(j + k, :), mat(i, :));
              end
          end
      end
      %remove all-zero rows if there are some
      mat = mat( sum(mat,2)&gt;0 ,:);
      if any(sum( mat(:,1:n) ,2)==0) % no solution because matrix A contains
          error('No solution.');  % all-zero row, but with nonzero RHS
      end
      rankA=rank(mat); %%Here
  
  end
  </code></pre>
  
  <p>Let check the matrix A at <a href="https://www.dropbox.com/s/glt4y90mfr6tq06/A.mat?dl=0" rel="nofollow">here</a>. Correct ans is 393 for rank of A.</p>