我正在尝试使用hdf5接口就地修改mat-file。
我有一个简单的mat-file,其中包含一个大小为K x L*M的2D数组,并希望将其重塑为一个大小为K x L x M的3D数组,而无需修改数据或数据类型。通常我会读取数据,执行val = reshape(val,K,L,M);并将其写回文件。但是,我可以通过简单地修改Dataset Size/MaxSize属性来实现这一点吗?
这是我到目前为止所拥有的;它看起来应该是有效的,但实际上并不是:
%%
val = rand(4,9);
save('test.mat','val','-v7.3');
h5disp('test.mat');
%%
fid = H5F.open('test.mat','H5F_ACC_RDWR','H5P_DEFAULT');
dset_id = H5D.open(fid,'/val');
space_id = H5D.get_space(dset_id);
H5S.set_extent_simple(space_id,3,fliplr([4,3,3]),fliplr([4,3,3]));
[ndims,h5_dims] = H5S.get_simple_extent_dims(space_id)
H5F.close(fid);H5disp-命令显示没有任何更改:
>> h5disp('test.mat')
Group '/'
Dataset 'val'
Size: 4x9
MaxSize: 4x9
Datatype: H5T_IEEE_F64LE (double)
ChunkSize: []
Filters: none
FillValue: 0.000000
Attributes:
'MATLAB_class': 'double'有什么想法吗?有没有更简单的方法?
发布于 2013-09-05 20:34:41
这是一个使用matlab的函数matfile的工作解决方案,该函数部分地读/写.mat文件。在这里,在.mat文件中对变量A进行了整形,而不加载它。
A = rand(2,3*4); %some data in A
save('A.mat', 'A','-v7.3'); %save variable A in A.mat
A1 = reshape(A,2,3,4); %create A1 as a reshape of A for later comparison
clear A %clear A
%modification of the variable within the .mat file
matObj = matfile('A.mat','Writable',true); %partial load of A
matObj.A = reshape(matObj.A,2,3,4); %reshape saved in A2
%comparison
load('A.mat'); %load the in-mat reshaped version of A
A2 = A;
isequal(A1, A2)https://stackoverflow.com/questions/18631743
复制相似问题