Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Matlab在HDF5数据集中写入复数_Matlab_Hdf5_Complex Numbers - Fatal编程技术网

使用Matlab在HDF5数据集中写入复数

使用Matlab在HDF5数据集中写入复数,matlab,hdf5,complex-numbers,Matlab,Hdf5,Complex Numbers,如何使用Matlab在HDF5数据集中写入复数 高级API()不支持复杂数据 % Write the matrix A (complex data) to HDF5. % Preserve the memory layout: what is contiguous in matlab (the % columns) remain contiguous in the HDF5 file (the rows). % In other words, the HDF5 dataset appears t

如何使用Matlab在HDF5数据集中写入复数

高级API()不支持复杂数据

% Write the matrix A (complex data) to HDF5.
% Preserve the memory layout: what is contiguous in matlab (the
% columns) remain contiguous in the HDF5 file (the rows).
% In other words, the HDF5 dataset appears to be translated.
%
% Adapted from https://support.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples/h5ex_t_cmpd.m


A = reshape((1:6)* (1 + 2 * 1i), 2, 3);

fileName = 'complex_example.h5';
datasetName = 'A';

%
% Initialize data. It is more efficient to use Structures with array fields
% than arrays of structures.
%
wdata = struct;
wdata.r = real(A);
wdata.i = imag(A);

%% File creation/opening
file = H5F.create(fileName, 'H5F_ACC_TRUNC', 'H5P_DEFAULT', 'H5P_DEFAULT');
%file = H5.open(fileName);

%% Datatype creation
%Create the complex datatype:
doubleType = H5T.copy('H5T_NATIVE_DOUBLE');
sz = [H5T.get_size(doubleType), H5T.get_size(doubleType)];

% Computer the offsets to each field. The first offset is always zero.
offset = [0, sz(1)];

% Create the compound datatype for the file and for the memory (same).
filetype = H5T.create ('H5T_COMPOUND', sum(sz));
H5T.insert (filetype, 'r', offset(1), doubleType);
H5T.insert (filetype, 'i', offset(2), doubleType);

%% Write data

% Create dataspace.  Setting maximum size to [] sets the maximum
% size to be the current size.
space = H5S.create_simple (ndims(A), fliplr(size(A)), []);

% Create the datasetName and write the compound data to it.
dset = H5D.create (file, datasetName, filetype, space, 'H5P_DEFAULT');
H5D.write (dset, filetype, 'H5S_ALL', 'H5S_ALL', 'H5P_DEFAULT', wdata);


%% Finalise
% Close and release resources.
H5D.close(dset);
H5S.close(space);
H5T.close(filetype);
H5F.close(file);