modify natural_connect.m to handle sparse matrix