writehdf5dataset
Writes data to the existing dataset. Errors out if dataset does not exist.
Syntax
writehdf5dataset(filename, datasetPath, data)
Inputs
- filename
- Path to the HDF5 file.
- datasetPath
- Fully qualified path of the dataset in the file.
- data
- Data to write.
Example 1
Dereference data read by
readhdf5.
output=readhdf5('plate_linear_static.hdf5','/OptiStruct/RESULT/Subcase 1/ELEMENT_FORCE/QUAD4');
createhdf5dataset('test.h5','/QUAD4',output{1,1})
writehdf5dataset('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
Write to dataset with logical/number/matrix/ndmatrix
data.
logical_data = true;
createhdf5dataset('test.h5','/logical_data',logical_data)
logical_data = false;
writehdf5dataset('test.h5','/logical_data',logical_data)
number_data=99;
createhdf5dataset('test.h5','/number_data',number_data)
number_data=78;
writehdf5dataset('test.h5','/number_data',number_data)
real_matrix_data = [1,2;3,4];
createhdf5dataset('test.h5','/real_matrix_data',real_matrix_data)
real_matrix_data = [11,21;31,41];
writehdf5dataset('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)
real_nd_matrix_data(1,2,1) = 199;
writehdf5dataset('test.h5','/real_nd_matrix_data',real_nd_matrix_data)
Example 3
Write dataset with complex data of
number/matrix/ndmatrix.
number_complex_data=99+8i;
createhdf5dataset('test.h5','/number_complex_data',number_complex_data)
number_complex_data=9+98i;
writehdf5dataset('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_matrix_complex_data = [11+13i,12+16i;13+18i,14+165i];
writehdf5dataset('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)
real_nd_matrix_complex_data(1,2,1) = 199+15i;
writehdf5dataset('test.h5','/real_nd_matrix_complex_data',real_nd_matrix_complex_data)
Example 4
Write dataset with string
data.
str_data = 'test string';
createhdf5dataset('test.h5','/str_data',str_data)
str_data = 'write test string';
writehdf5dataset('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)
str_data_cell{2,2} = 'write test string 2,2';
writehdf5dataset('test.h5','/str_data_cell',str_data_cell)
Example 5
Write dataset with struct
data.
struct_data = struct('field_name1', 99, 'field_name2', 'test string');
createhdf5dataset('test.h5','/struct_data',struct_data)
struct_data = struct('field_name1', 19, 'field_name2', 'write test string');
writehdf5dataset('test.h5','/struct_data',struct_data)
Example 6
Write object reference to an existing
dataset.
output=readhdf5('spice_inv2.dhdf','/Model/Variables');
%modify object reference
((output{1,1}).('objectId'))(71) = 98215;
writehdf5dataset('spice_inv2.dhdf','/Model/Variables',output{1,1});
Comments
Known limitations include:
- Object references read using the readhdf5 command are written as object references if existing dataset values are object references.
- Writing nested compound data is only supported for OML data types logical/numbers.
- Data read using the readhdf5 command should be dereferenced. See Example 1.