Are all the relationships position based?
What format do you need for this data so your "other application" can use it to create the final matrix?
In very general terms, if you have a table of layers with one record for each layer and a serial number to identify each layer uniquely, you can set up a related table for listing the layers to which you want to link it and to describe the nature of that relationship. This new related table can then link to a second occurrence of your Layers table, if needed to show information about each related layer.
Layers----<LayerLinks>-----LinkedLayers (LinkedLayers is an added occurrence of Layers)
Layers::__pkLayerID = LayerLinks::_fkLayerID
LinkedLayers::__pkLayerID = LayerLinks::_fkLinkedLayerID
A portal to LayerLinks can be put on the Layers table to list all related layers. Fields from LinkedLayers can be added to the portal row to show more info about that layer and _fkLinkdeLayerID can be put in this portal row formatted as a drop down list or pop up menu so that you can select a Layer record to link to the current layer record on your layout.