且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在MATLAB中更改HDF5文件中的数据类型?

更新时间:2022-12-08 11:52:46

无法删除数据集或更改其数据类型.摘自 HDF5手册:

It is not possible to either delete a dataset or change its datatype. From section 5.3.2 of the HDF5 manual:

The datatype is set when the dataset is created and can never be changed.

这是由于HDF5文件中的空间分配方式所致.由于相同的原因,虽然无法删除数据集,但可以将其取消链接"并使其不可访问,但这不会回收已使用的空间.

This is due to how space is assigned in an HDF5 file. While it's not possible to delete a dataset (for the same reasons), it can be "unlinked" and be made inaccessible, but this does not reclaim the used space.

如果确实需要更改数据类型,则有两种选择:第一种是取消链接旧数据集并在其位置创建一个新数据集.新的数据集可以与旧的数据集具有相同的名称.但是,如果您担心空间不足,则可能更喜欢只创建一个全新的HDF5文件,然后将旧数据复制到新文件中.

If you really need to change the datatype, you have two choices: the first is to unlink the old dataset and create a new one in its place. The new dataset can have the same name as the old one. However, if space is a concern, you may prefer to just create an entirely new HDF5 file, and copy the old data into the new one.