如何在MATLAB中更改HDF5文件中的数据类型? [英] How do I change the data type in an HDF5 file from MATLAB?

查看:516
本文介绍了如何在MATLAB中更改HDF5文件中的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HDF5数据文件,该文件具有一个int32数据值数组.我希望将存储在该数组中的数据更改为具有不同格式(双精度)的不同值.

I have a HDF5 datafile that has an array of int32 data values. I wish to change the data stored in that array to different values which are of a different format (double).

例如,我可以使用以下查询数据类型:

for example I can query the data type with the following:

 finf=h5info('file.hdf5');
 finf.Datasets(1).Datatype

 ans = 

      Name: ''
      Class: 'H5T_INTEGER'
      Type: 'H5T_STD_I32LE'
      Size: 4
      Attributes: []

如果我尝试在同一节点位置上重新创建数据,则会出现以下错误:该数据集已存在:

If I try to recreate the data in the same node location it gives me the following error that the data set already exists:

t=double(h5read([filepath filename],'/t'));

% more t calculations here....

h5create('file.hdf5','/t',size(t),'DataType','double');

Error using h5create>create_dataset (line 159)
The dataset '/t' already exists.

Error in h5create (line 69)
create_dataset(options);

我在Matlab文档中寻找了用于删除hdf5文件中的数据集的函数,但找不到任何引用.有人有想法吗?

I've looked in the Matlab docs for a function for deleting a data set in an hdf5 file but can't find any references. Any one have any ideas?

推荐答案

无法删除数据集或更改其数据类型.摘自 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.

这篇关于如何在MATLAB中更改HDF5文件中的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆