Given a matrix such as:
A←0 1 1 0 1⍀1 0 0 1 1\3 3⍴⍳9
Which is:
0 0 0 0 0
1 0 0 2 3
4 0 0 5 6
0 0 0 0 0
7 0 0 8 9
Empty rows and columns can be removed with:
(0∨.≠B)/B←(A∨.≠0)⌿A
Output:
1 2 3
4 5 6
7 8 9
Trim only the outsides:
Trim leading and trailing columns:
(∨\0∨.≠B)/B←(⌽∨\⌽0∨.≠A)/A
Trim leading and trailing rows:
(-2↑+/^\⌽B^.=0)↓B←(∨\A∨.≠0)⌿A
All together:
(-2↑+/^\⌽D^.=0)↓D←(∨\C∨.≠0)⌿C←(∨\0∨.≠B)/B←(⌽∨\⌽0∨.≠A)/A