HDF5 transpose data?

조회 수: 11 (최근 30일)
Nycholas Maia
Nycholas Maia 2019년 10월 23일
답변: Anudeep Kumar 2025년 6월 3일
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?
matlab.jpg
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

답변 (1개)

Anudeep Kumar
Anudeep Kumar 2025년 6월 3일
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')';

카테고리

Help CenterFile Exchange에서 HDF5에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by