IT评测·应用市场-qidao123.com

标题: c++ 与 Matlab 程序的数据比对 [打印本页]

作者: 花瓣小跑    时间: 2025-1-24 04:24
标题: c++ 与 Matlab 程序的数据比对
背景

***避免数据精度毛病,快速对比变量 ***
环境

c++下载 https://github.com/BlueBrain/HighFive
以及hdf5库
在vs 中设置库

数据保存

  1. #include <highfive/highfive.hpp>
  2. using namespace HighFive;
  3. std::string filename1 = "test.h5";
  4. File file1(filename1, File::Truncate);
  5. //保存数据
  6. file1.createDataSet("TempMS2Mz_SubRun" , TempMS2Mz_SubRun);
复制代码
  1. % 定义 HDF5 文件路径
  2. h5_file_path = 'example.h5';
  3. % 写入第一个数据集
  4. data1 = rand(3, 3);
  5. h5create(h5_file_path, '/dataset1', size(data1));
  6. h5write(h5_file_path, '/dataset1', data1);
  7. % 写入第二个数据集
  8. data2 = magic(4);
  9. h5create(h5_file_path, '/dataset2', size(data2));
  10. h5write(h5_file_path, '/dataset2', data2);
  11. disp('多个数据集已写入 HDF5 文件。');
复制代码
数据加载

  1. #include <highfive/highfive.hpp>
  2. using namespace HighFive;
  3. std::string filename1 = "test.h5";
  4. File file1(filename1, HighFive::File::ReadOnly);
  5. auto dataset = file.getDataSet("grp/data");
  6. // Read back, automatically allocating:
  7. auto data = dataset.read<std::vector<int>>();
  8. // Alternatively, if `data` has the correct
  9. // size, without reallocation:
  10. dataset.read(data);
复制代码
  1. % 定义 HDF5 文件路径
  2. h5_file_path = 'example.h5';
  3. % 读取第一个数据集
  4. data1 = h5read(h5_file_path, '/dataset1');
  5. disp('dataset1:');
  6. disp(data1);
  7. % 读取第二个数据集
  8. data2 = h5read(h5_file_path, '/dataset2');
  9. disp('dataset2:');
  10. disp(data2);
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4