最近做的项目中,需要对输入图像做预处理,可是在C++中直接对图片操作不直观,所以想先把图片打包在matlab上做处理之后再输入到C++工程中的网络中使用。
1.在vs中将数据写入指定文件
double* ptr_array;
int temp = _msize(ptr_array) / sizeof(double);
FILE * fp;
fp = fopen("dataset.dat", "wb");
if (fp == NULL)
printf("cant open the file");
fwrite(ptr_array, sizeof(double), temp, fp);
fclose(fp);
fp = NULL;
ptr_array为double型数组指针,使用fwrite讲数据写入dat文件中。
2.在matlab中读取文件数据
file = fopen('dataset.dat','r');
[spikeRate, count] = fread(file, 'double');