File Exchange

image thumbnail

HDF5 data to struct reader

version 1.1.0.0 (1.08 KB) by Pauli Virtanen
Read datasets and groups from a HDF5 file to a Matlab structure conveniently

6 Downloads

Updated 28 Apr 2009

View Version History

No License

This function loads data from a HDF5 file (or optionally a selected part of it) to a Matlab structure. Nested groups are supported, and included as structs nested inside structs.

It can read all data the low-level HDF5 API can handle. (Matlab's own high-level hdf5* can't read for example chunked datasets, at least as of R2008a.)

Complex numbers are also supported; compound datasets with two fields 'r' and 'i' interpreted as complex numbers.

The function also preserves the order of dimensions in the data read, ie., it permutes the data from C order (that's in the file) to Fortran order (Matlab). This is useful when reading HDF5 files generated by non-Matlab software.

Cite As

Pauli Virtanen (2021). HDF5 data to struct reader (https://www.mathworks.com/matlabcentral/fileexchange/23934-hdf5-data-to-struct-reader), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

Aram Vartanyan

Hmmm, it just output me an empty struct :/

Qianqian Fang

New URL for the EasyH5 toolbox to read/write almost any MATLAB data types to HDF5: https://www.mathworks.com/matlabcentral/fileexchange/72918-easyh5-an-easy-to-use-hdf5-data-interface-loadh5-saveh5

Qianqian Fang

FYI, I modified this script to also read attribute data; also added a saving to H5 function - saveh5, you can find both in this updated toolbox EazyH5

https://www.mathworks.com/matlabcentral/fileexchange/72820-eazyh5-an-easy-to-use-hdf5-data-interface-loadh5-saveh5

Bas-Jan Zandt

had to add
if ischar(data)
data = permute(data, fliplr(1:ndims(data)));
end
at then end of function data=fix_data(data) section

Björn S.

Works great after correcting the objtype problem

Ivy

In the "function data=fix_data(data)" section added the following code to fix the char array dimension problem.

for i=1:length(fields)
f = data.(fields{i});
if ischar(f)
f = permute(f, fliplr(1:ndims(f)));
data.(fields{i})= f;
end
end

Ivy

Does not work for newer version of MATLAB.
I added the following code to make it work for MATLAB (R2009b) and later version.

% objtype index factory according to matlab version
v = ver('MATLAB');
if datenum(v.Date)>datenum('04-Aug-2008')
objtype = objtype+1;
end

Ivy

Very convenient to use!!! Thanks!

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: EasyH5

Community Treasure Hunt

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

Start Hunting!