added code for analyzing matrices