Thank you for the image.
You show beam elements meshed on line bodies.
You have correctly drawn each line around the unit cube. Note for others reading this, a common mistake is to draw one long vertical line.
A simple way for you to connect these elements at the intersection points is to use Node Merge. Right click on the Mesh and Insert a Node Merge Group. Type in a Tolerance value then right click on the folder and select Detect Connections, the folder will fill with connections. Then right click and Generate, that will replace multiple coincident nodes with a single node.
If the lines were drawn in SpaceClaim, you would create Shared Topology by going to the Workbench tab and clicking on the Share button, which would create a shared node at each intersection, then you would not need to use Node Merge.
Shared Topology can also be created in DesignModeler.
Several discussions have appeared on this site on how to export the mass and stiffness matrix out of ANSYS for use in matlab or other programs.
Please see documentation on SEOPT. Open ANSYS Help, then copy/paste the URL below into the Help address bar.
You can insert code into Mechanical using a Command Object. The following should get you both stiffness and mass.
seopt, file, 2, 1
Here is a video from ANSYS from 2018.