check_matrix(A) --- check if A is a valid adjacency matrix for a graph
SYNOPSIS
function ok = check_matrix(A)
DESCRIPTION
check_matrix(A) --- check if A is a valid adjacency matrix for a graph
CROSS-REFERENCE INFORMATION
This function calls:
This function is called by:
SOURCE CODE
0001 function ok = check_matrix(A)
0002 % check_matrix(A) --- check if A is a valid adjacency matrix for a graph
0003
0004 ok = 0;
0005
0006 % make sure matrix is equare
0007 [nr,nc] = size(A);
0008 if (nr ~= nc)
0009 return
0010 end
0011
0012 % see if the matrix is zero-one
0013 B = (A>0); % convert to logical (so 0,1).
0014 if (nnz(A-B)>0)
0015 return
0016 end
0017
0018 % check if symmetric
0019 if (nnz(A-A')>0)
0020 return
0021 end
0022
0023 % check the diagonal
0024 if (any(diag(A)>0))
0025 return
0026 end
0027
0028 % all tests passed
0029 ok = 1;