HDF4: Porting from hdfsd to hdfread

12 Ansichten (letzte 30 Tage)
Mathew Owens
Mathew Owens am 16 Mai 2018
Kommentiert: Mathew Owens am 28 Feb. 2022
I'm having trouble porting old code from the now obsolete HDFSD to the new hdfread (MATLAB.IO.HDF4.SD)
Previously, I'd open a HDF file for input, get the number of datasets present and then read them in one by one:
sd_id = hdfsd( 'start',filepath, 'rdonly' );
[ndatasets,nglobal_attr,status] = hdfsd('fileinfo',sd_id);
for icnt=0:(ndatasets-1)
sds_id = hdfsd( 'select', sd_id, icnt );
<read each dataset in to a variable>
end
Using hdfread, I can't seem to access anything but the 0th datafile. Any ideas? The documentation doesn't seem to cover this, and I can't "see" other datafiles using hdftool.

Akzeptierte Antwort

Mathew Owens
Mathew Owens am 16 Mai 2018
Bearbeitet: Mathew Owens am 16 Mai 2018
.... and of course, an extra couple of hours monkeying around and I figure it out. Just in case anyone else has a similar issue in the future, here's the solution:
sdID = sd.start(filepath,'read');
[ndatasets,ngatts] = sd.fileInfo(sdID);
for icnt=0:(ndatasets-1)
sdsID = sd.select(sdID,icnt);
data=sd.readData(sdsID);
sd.endAccess(sdsID);
sd.close(sdID);
end
  3 Kommentare
Piyush Ojha
Piyush Ojha am 28 Feb. 2022
why it is showing
Undefined variable "sd" or class "sd.start".
Please help
Mathew Owens
Mathew Owens am 28 Feb. 2022
Sorry, no idea. I moved over to python some time ago.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by