How to create a distance matrix using the HC-SR04 sensor?

Perhaps your underlying method is wrong then.