背景
***避免数据精度毛病,快速对比变量 ***
环境
c++下载 https://github.com/BlueBrain/HighFive
以及hdf5库
在vs 中设置库
数据保存
- #include <highfive/highfive.hpp>
- using namespace HighFive;
- std::string filename1 = "test.h5";
- File file1(filename1, File::Truncate);
- //保存数据
- file1.createDataSet("TempMS2Mz_SubRun" , TempMS2Mz_SubRun);
复制代码- % 定义 HDF5 文件路径
- h5_file_path = 'example.h5';
- % 写入第一个数据集
- data1 = rand(3, 3);
- h5create(h5_file_path, '/dataset1', size(data1));
- h5write(h5_file_path, '/dataset1', data1);
- % 写入第二个数据集
- data2 = magic(4);
- h5create(h5_file_path, '/dataset2', size(data2));
- h5write(h5_file_path, '/dataset2', data2);
- disp('多个数据集已写入 HDF5 文件。');
复制代码 数据加载
- #include <highfive/highfive.hpp>
- using namespace HighFive;
- std::string filename1 = "test.h5";
- File file1(filename1, HighFive::File::ReadOnly);
- auto dataset = file.getDataSet("grp/data");
- // Read back, automatically allocating:
- auto data = dataset.read<std::vector<int>>();
- // Alternatively, if `data` has the correct
- // size, without reallocation:
- dataset.read(data);
复制代码- % 定义 HDF5 文件路径
- h5_file_path = 'example.h5';
- % 读取第一个数据集
- data1 = h5read(h5_file_path, '/dataset1');
- disp('dataset1:');
- disp(data1);
- % 读取第二个数据集
- data2 = h5read(h5_file_path, '/dataset2');
- disp('dataset2:');
- disp(data2);
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |