HDF5 transpose data?
1 view (last 30 days)
Show older comments
I have a HDF5 file called "output.h5" and it have a dataset called "density" which is a matrix with 21 rows and 2 cols.
I read this HDF5 dataset, but I got the transposed version of my density matrix (2 rows, 21 cols). Why? How can I solve it?

Here is my HDF5 dump of this file:
h5dump output.h5
HDF5 "output.h5" {
GROUP "/" {
GROUP "my" {
GROUP "path" {
GROUP "to" {
DATASET "density" {
DATATYPE H5T_IEEE_F64LE
DATASPACE SIMPLE { ( 21, 2 ) / ( 21, 2 ) }
DATA {
(0,0): 0, 2,
(1,0): 1, 2,
(2,0): 2, 4,
(3,0): 3, 8,
(4,0): 4, 14,
(5,0): 5, 22,
(6,0): 6, 32,
(7,0): 7, 44,
(8,0): 8, 58,
(9,0): 9, 74,
(10,0): 10, 92,
(11,0): 11, 112,
(12,0): 12, 134,
(13,0): 13, 158,
(14,0): 14, 184,
(15,0): 15, 212,
(16,0): 16, 242,
(17,0): 17, 274,
(18,0): 18, 308,
(19,0): 19, 344,
(20,0): 20, 382
}
}
}
}
}
}
}
Thanks
0 Comments
Answers (1)
Anudeep Kumar
on 3 Jun 2025
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')';
0 Comments
See Also
Categories
Find more on HDF5 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!