title: Building adjacency matrix from faces array
body: <p>I am using this <a href="https://de.mathworks.com/matlabcentral/fileexchange/36316-local-depth-sift-and-scale-invariant-spin-image-local-features-for-3d-meshes" rel="nofollow noreferrer">code</a> used in a toolbox for calculating adjacency matrix from a set of faces. My <code>faces</code> is an <code>m*3</code> array for example:</p>
  
  <pre><code>23  13  12
  12  22  23
  13  4   12
  23  14  13
  22  35  23
  </code></pre>
  
  <p>From  what I have understood, the adjacency matrix should be an <code>nxn</code> matrix where <code>n</code> is the number of vertices. For some of my mesh .ply files I get adjacency matrix which has a smaller dimension than the number of vertices. For example, <code>n=5047</code> but my adjacency matrix has dimensions <code>nxn= 4719x4719</code>.</p>
  
  <p>What could be the reason for this behavior? I get this error not on all but some mesh files only.</p>
  
  <p>The code:</p>
  
  <pre><code>function A = triangulation2adjacency(face,vertex)
  % triangulation2adjacency - compute the adjacency matrix
  %   of a given triangulation.
  %
  %   A = triangulation2adjacency(face);
  % or for getting a weighted graph
  %   A = triangulation2adjacency(face,vertex);
  %
  %   Copyright (c) 2005 Gabriel Peyr
  
  
  [tmp,face] = check_face_vertex([],face);
  f = double(face)';
  
  A = sparse([f(:,1); f(:,1); f(:,2); f(:,2); f(:,3); f(:,3)], ...
         [f(:,2); f(:,3); f(:,1); f(:,3); f(:,1); f(:,2)], ...
         1.0);
  % avoid double links
  A = double(A&gt;0);
  
  return; 
  
  
  nvert = max(max(face));
  nface = size(face,1);
  A = spalloc(nvert,nvert,3*nface);
  
  for i=1:nface
      for k=1:3
          kk = mod(k,3)+1;
          if nargin&lt;2
              A(face(i,k),face(i,kk)) = 1;
          else
              v = vertex(:,face(i,k))-vertex(:,face(i,kk));
              A(face(i,k),face(i,kk)) = sqrt( sum(v.^2) );    % euclidean distance
          end
      end
  end 
  % make sure that all edges are symmetric
  A = max(A,A');
  </code></pre>