HDF5 transpose data?

10 ビュー (過去 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 Center および File ExchangeHDF5 についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by