in a project I am developing I have a matrix of cells, each cell containing 3 buttons (it will be more eventually, around 10). The schematic is like this:

[![enter image description here](https://i.stack.imgur.com/yUkyz.png)](https://i.stack.imgur.com/yUkyz.png)

I want to read each one of the cells, and in each cell I want to read each one of the buttons. To do it, I want to multiplex each cell, and read the first button on the MuxBTN1 pin, the second on the MuxBTN2 pin, etc. I also want it to be expandable, the matrix will be NxM sizewise (the number of cells will be around 30-40).
Each button is a bit, each cell is an 10 bit number, I want to map all the cells numbers to a bi dimensional matrix in code. Speed is not very important.

What would be a good approach to this problem? Everything I have found on the internet was about multiplexing an led matrix, which is not the same. Thank you!