Hey Nycholas,
I believe this maybe due to the difference in the way different languages store data. C uses row-major and MATLAB uses column-major to store data. So when you read a dataset from an HDF5 file in MATLAB, the dimensions may appear transposed.
There is a detailed discussion on the same in the following MATLAB Answer link :
You can use the transpose operator to obtain data in your intended shape as follows
data = h5read('output.h5', '/my/path/to/density')';