createhdf5dataset
Creates a new dataset and writes data. Errors out if dataset exists; creates file if it doesn't exist.
Syntax
createhdf5dataset(filename, datasetPath, data)
createhdf5dataset(filename, datasetPath, data, chunk)
Inputs
- filename
- Path to the HDF5 file.
- datasetPath
- Fully qualified path of the dataset in the file.
- data
- Data to write.
- chunk
- Optional. Chunk size. 1*N matrix, where N is the number of dimensions of data.
Example 1
output=readhdf5('plate_linear_static.hdf5','/OptiStruct/RESULT/Subcase 1/ELEMENT_FORCE/QUAD4');
createhdf5dataset('test.h5','/QUAD4',output{1,1})
output=readhdf5('test.h5','/QUAD4')
output =
{
[1,1] struct [
BMX: [Matrix] 10000 x 1 Rows[1:30] Column[1]
151.80786
156.49155
161.25160
147.32631
149.64325
156.68770
....
]
}
Example 2
logical_data = true;
createhdf5dataset('test.h5','/logical_data',logical_data)
number_data=99;
createhdf5dataset('test.h5','/number_data',number_data)
real_matrix_data = [1,2;3,4];
createhdf5dataset('test.h5','/real_matrix_data',real_matrix_data)
real_nd_matrix_data(2,3,4) = 9;
real_nd_matrix_data(1,2,3) = 97;
real_nd_matrix_data(1,3,2) = 98;
real_nd_matrix_data(1,2,1) = 99;
createhdf5dataset('test.h5','/real_nd_matrix_data',real_nd_matrix_data)
Example 3
number_complex_data=99+8i;
createhdf5dataset('test.h5','/number_complex_data',number_complex_data)
real_matrix_complex_data = [1+3i,2+6i;3+8i,4+65i];
createhdf5dataset('test.h5','/real_matrix_complex_data',real_matrix_complex_data)
real_nd_matrix_complex_data(2,3,4) = 9+7i;
real_nd_matrix_complex_data(1,2,3) = 97+5i;
real_nd_matrix_complex_data(1,3,2) = 98+6i;
real_nd_matrix_complex_data(1,2,1) = 99+5i;
createhdf5dataset('test.h5','/real_nd_matrix_complex_data',real_nd_matrix_complex_data)
Example 4
str_data = 'test string';
createhdf5dataset('test.h5','/str_data',str_data)
str_data_cell{1,1} = 'test string 1,1';
str_data_cell{1,2} = 'test string 1,2';
str_data_cell{2,1} = 'test string 2,1';
str_data_cell{2,2} = 'test string 2,2';
createhdf5dataset('test.h5','/str_data_cell',str_data_cell)
Example 5
struct_data = struct('field_name1', 99, 'field_name2', 'test string');
createhdf5dataset('test.h5','/struct_data',struct_data)
Example 6
data=rand(900,400);
createhdf5dataset('test.h5','/data_user_preferred_chunk',data,[300,200])
Example 6
output=readhdf5('spice_inv2.dhdf','/Model/Variables');
%modify object reference
((output{1,1}).('objectId'))(71) = 98215;
createhdf5group('spice_inv2_new.dhdf','/Model');
%To new dataset object references (e.g objectId) is written as floating point number
createhdf5dataset('spice_inv2_new.dhdf','/Model/Variables',output{1,1});
Comments
- Creates chunked dataset.
- Object references read using the readhdf5 command are written as double to new dataset.
- Parent group of dataset should exist except if parent is a root group.
- Writing nested compound data is only supported for OML data types logical/numbers.
- Data read using readhdf5 command should be dereferenced. See Example 1.
- If data is complex, an attribute with the name omlcomplex is added to the dataset, which is used while reading the dataset using the readhdf5 command.